PHP 找不到 Stomp 类 [英] Php Can't find Stomp class

查看:42
本文介绍了PHP 找不到 Stomp 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 客户端从 activemq 获取队列.我在项目中包含了一个 stomp 库.这是我的项目树:

I'm trying to get a queue from activemq using a PHP client. I included in the project a stomp library. Here is my project tree:

TestPhp/
├── PhpInfo.php
├── SimpleStompConsumer.php
└── Stomp
    ├── Exception
    |   └── StompException.php
    ├── ExceptionInterface.php
    ├── Frame.php
    ├── Message
    │   ├── Bytes.php
    │   └── Map.php
    ├── Message.php
    └── Stomp.php

这是我的代码

<?php
$path = "/var/www/test/TestPhp/Stomp/Stomp.php";

require_once($path);
$con = new Stomp("tcp://localhost:61613");
$con->connect();
$con->subscribe("/queue/test");
$msg = $con->readFrame();


if( $msg != null) {
    echo "Received message with body '$msg->body'\n";
    $con->ack($msg);
} else {
echo "Failed to receive a message\n";
}
$con->disconnect();

?>

当我运行 php 文件时,出现以下错误,我不知道该怎么办.PHP 致命错误:在第 5 行的/var/www/test/TestPhp/SimpleStompConsumer.php 中找不到Stomp"类PHP 堆栈跟踪:PHP 1. {main}()/var/www/test/TestPhp/SimpleStompConsumer.php:0

When I run the php file I get the following error and I don' know what to do. PHP Fatal error: Class 'Stomp' not found in /var/www/test/TestPhp/SimpleStompConsumer.php on line 5 PHP Stack trace: PHP 1. {main}() /var/www/test/TestPhp/SimpleStompConsumer.php:0

我很感激任何指令.谢谢.

I'd appreciate any directives. Thanks.

Edit:  

库被称为 Stomp.这里是github 链接和 下载 链接

Library is called Stomp. Here is the github link and the download link

Edit:

更改 $con = new Stomp("tcp://localhost:61613");to $con = new FuseSource\Stomp\Stomp("tcp://localhost:61613"); $con = new FuseSource\Stomp\Stomp("tcp://localhost:61613");

Change $con = new Stomp("tcp://localhost:61613"); to $con = new FuseSource\Stomp\Stomp("tcp://localhost:61613"); $con = new FuseSource\Stomp\Stomp("tcp://localhost:61613");

ERROR returned: 

PHP 致命错误:在第 174 行的/var/www/test/TestPhp/Stomp/Stomp.php 中找不到FuseSource\Stomp\Exception\StompException"类PHP 堆栈跟踪:PHP 1. {main}()/var/www/test/TestPhp/SimpleStompConsumer.php:0PHP 2. FuseSource\Stomp\Stomp->connect()/var/www/test/TestPhp/SimpleStompConsumer.php:6PHP 3. FuseSource\Stomp\Stomp->_makeConnection()/var/www/test/TestPhp/Stomp/Stomp.php:195

推荐答案

Stomp 库是一个 composer 包,所以你需要 Composer 类加载器或任何其他兼容 PSR-0 的,参见这个 https://getcomposer.org/doc/01-basic-usage.md.

Stomp library is a composer package, so you need composer class loader or any other PSR-0 compatible, see this https://getcomposer.org/doc/01-basic-usage.md.

来自 PHP-Fig 的 PSR-0 类加载器示例:https://gist.github.com/jwage/221634

Example PSR-0 class loader from PHP-Fig: https://gist.github.com/jwage/221634

require_once 'path_to_spl_class_loader.php';
$loader = new SplClassLoader('FuseSource\Stomp', __DIR__.'/Stomp');
$loader->register();
new FuseSource\Stomp\Stomp();

除了它的命名空间类之外,将此行添加到您的文件中:

Besides it's namespaced class, add this line to you file:

use FuseSource\Stomp\Stop;
new Stomp();

或者使用

new FuseSource\Stomp\Stomp();

这篇关于PHP 找不到 Stomp 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆