PHP AMQP Consume() fork 做实际工作

标签 php rabbitmq amqp

我正在寻找一个从 RabbitMQ 队列消费(使用 PECL AMQP 模块)然后 fork 以完成实际工作的 PHP 脚本。

我有代码@https://gist.github.com/giggsey/6666e67bb0e090eeb5f0

但是当我运行它时,我得到:

11296 Key: USER.12392 ObjectLength: 74 Forked 11296 at 2013-03-19

14:16:22 11277 ack() PHP Fatal error: Uncaught exception

'AMQPConnectionException' with message 'Connection reset by peer' in tmp/forking.php:10

Stack trace:

0 tmp/forking.php(10): AMQPQueue->consume(Array)

1 tmp/forking.php(102): test->run()

2 {main} thrown in tmp/forking.php on line 10

Fatal error: Uncaught exception 'AMQPConnectionException' with message 'Connection reset by peer' in tmp/forking.php on line 10

AMQPConnectionException: Connection reset by peer in tmp/forking.php on line 10

Call Stack:

0.0006     665008   1. {main}() tmp/forking.php:0

0.0007     665456   2. test->run() tmp/forking.php:102

0.0359     670504   3. AMQPQueue->consume() tmp/forking.php:10

最佳答案

建立连接后你fork,这意味着子继承连接,这样父和所有子最终使用相同的连接,如果任何子退出(自动关闭连接)或关闭连接, parent 和所有 sibling 突然发现他们不再有联系。

所以不要使用:

$connection->connect();

使用记录较少的:

$connection->pconnect();

这将提供持久连接,这样当 fork 的子节点关闭连接时,父节点会自动重新打开它。

关于PHP AMQP Consume() fork 做实际工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502037/

相关文章:

php - 如何从php上传文件到amqp

javascript - 如何使用 ajax-jquery 将选定的复选框数据获取到使用 PHP-CodeIgniter 的模态

phpmyadmin返回查询结果但php返回0

docker - 无法在 Docker 文件中添加 rabbitmq 用户

mule - 当通过 HTTP 请求触发时,无法使用 Mule Requester 使用 AMQP 消息

c++ - 具有最小依赖性的跨平台 C/C++ RabbitMQ 库

php - 如何在 php 中不显示 cURL 响应数据?

php - 仅当 count rows 等于 x 时才执行插入查询

activemq - 从 ActiveMQ 切换到 RabbitMQ

java - 使用 RabbitMQ 节流 AMQP 消费者