0

我正在尝试通过我的 CPanel 上的计划任务创建与 CloudAMQP 的连接,当我 SSH 到服务器并手动运行脚本时它工作正常,但是当我尝试通过调度程序运行时,我得到了这个:

PHP Fatal error: Uncaught PhpAmqpLib\Exception\AMQPIOException: stream_socket_client(): unable to connect to tcp://xxxxx.rmq.cloudamqp.com:5672 (Connection refused) in /home/sites/xx/x/xxx/public_html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:111
Stack trace:
#0 home/sites/xx/x/xxx/public_html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(245): PhpAmqpLib\Wire\IO\StreamIO->connect()
#1 home/sites/xx/x/xxx/public_html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(228): PhpAmqpLib\Connection\AbstractConnection->connect()
#2 home/sites/xx/x/xxx/public_html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AMQPStreamConnection.php(61): PhpAmqpLib\Connection\AbstractConnection->__construct('xxxxx', 'xxxxxx...', 'xxxxxxx', false, 'AMQPLAIN', Object(PhpAmqpLib\Wire\AMQPWriter), 'en_US', Object(PhpAmqpLib\Wire\IO\StreamIO), 0, 3, 0)
#3 /home/sites/xxxxx/x/xxxxxx/public_html/xxxxx/cloudamqp in /home/sites/xxx/xxxx/xxxxx/public_html/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 111

我的 PHP 代码如下所示:

$url = parse_url("amqps://xxxxx:paswordherexxxs@lionhead.rmq.cloudamqp.com/somethinglikethis");
$vhost = substr($url['path'], 1);

$conn = new AMQPStreamConnection("$url['host']", 5672, $url['user'], $url['pass'], $vhost);

$ch = $conn->channel();

$exchange = 'amq.direct';
$queue = 'queue-name';
$ch->queue_declare($queue, false, true, false, false);
$ch->exchange_declare($exchange, 'direct

老实说,我很难过。第一个大型 PHP 项目(学习编码),我迷路了。

4

0 回答 0