与RabbitMQ断开连接后,Apache进程不会死亡

我试图在我的项目中使用服务器端事件机制。 (这就像长期投票类固醇)

从“ 从服务器发送事件 ”字幕的例子工作得很好。 几秒钟后,断开连接,apache进程被终止。 这种方法工作正常。

但! 如果我尝试使用RabbitMQ ,则在浏览器从服务器( es.close() )断开连接后,Apache不会导致进程中断。 并且进程保持原样并在docker容器重新启动后才被杀死。

connection_aborted和connection_status根本不起作用。 connection_aborted仅返回0 ,connection_status即使在断开CONNECTION_NORMAL后也返回CONNECTION_NORMAL 。 只有当我使用RabbitMQ时才会发生。 没有RMQ这个function运作良好。

ignore_user_abort(false)也不起作用。

代码示例:

 <?php use PhpAmqpLib\Channel\AMQPChannel; use PhpAmqpLib\Connection\AbstractConnection; use PhpAmqpLib\Exception\AMQPTimeoutException; use PhpAmqpLib\Message\AMQPMessage; class RequestsRabbit { protected $rabbit; /** @var AMQPChannel */ protected $channel; public $exchange = 'requests.events'; public function __construct(AbstractConnection $rabbit) { $this->rabbit = $rabbit; } public function getChannel() { if ($this->channel === null) { $channel = $this->rabbit->channel(); $channel->exchange_declare($this->exchange, 'fanout', false, false, false); $this->channel = $channel; } return $this->channel; } public function send($message) { $channel = $this->getChannel(); $message = json_encode($message); $channel->basic_publish(new AMQPMessage($message), $this->exchange); } public function subscribe(callable $callable) { $channel = $this->getChannel(); list($queue_name) = $channel->queue_declare('', false, false, true, false); $channel->queue_bind($queue_name, $this->exchange); $callback = function (AMQPMessage $msg) use ($callable) { call_user_func($callable, json_decode($msg->body)); }; $channel->basic_consume($queue_name, '', false, true, false, false, $callback); while (count($channel->callbacks)) { if (connection_aborted()) { break; } try { $channel->wait(null, true, 5); } catch (AMQPTimeoutException $exception) { } } $channel->close(); $this->rabbit->close(); } } 

怎么了:

  • 浏览器build立到服务器的SSE连接。 var es = new EventSource(url);
  • Apache2产生新的进程来处理这个请求。
  • PHP生成一个新的队列并连接到它。
  • 浏览器closures连接es.close()
  • Apache2不会终止进程并保持原样。 RabbitMQ队列不会被删除。 如果我做一些重新连接,它会产生一堆进程和一堆队列(1重新连接= 1进程= 1队列)。
  • 我closures所有选项卡 – 进程活着。 我closures浏览器 – 相同的情况。

看起来行某种PHP的错误。 还是Apach2?

我使用的是:

  • 最后的docker和docker组成
  • PHP:7.1.12-apache或php:5.6-apache图像(这发生在两个版本的PHP上)

一些截图:

RabbitMQ队列

流程

请帮我弄清楚发生了什么事

PS对不起,我的英语。 如果您发现错误或错字,请在评论中指出。 我会非常感激:)