|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-14 15:19 UTC] bkw@php.net
[2013-01-14 16:01 UTC] pineain at gmail dot com
[2013-01-14 16:08 UTC] bogdan dot albei at gmail dot com
[2013-01-14 17:05 UTC] bkw@php.net
[2013-05-12 15:23 UTC] bkw@php.net
[2013-05-12 15:23 UTC] bkw@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: bkw
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 04:00:01 2025 UTC |
Description: ------------ If you have a long running script(daemon) consuming messages by using the AMQPQueue::consume, then a RabbitMQ consumer is created for every message consumed. This is not a problem on web requests because the AQMP connection is destroyed at the end of the request. This leads to high memory consumption for RabbitMQ and potentially for the consumer PHP script. In order to test this you need to have the consumer running(script attached) and then enqueue messages by using the producer(script attached). A workaround for this is to disconnect and reconnect to RabbitMQ, but that has its own overhead. Test script: --------------- Producer: <?php $routingKey = 'routing.key'; $exchangeName = 'myexchange'; $queueName = 'testQueue'; $message = 'test'; $connection = new AMQPConnection(); $connection->connect(); $channel = new AMQPChannel($connection); $exchange = new \AMQPExchange($channel); $exchange->setName($exchangeName); $exchange->setType(AMQP_EX_TYPE_DIRECT); $exchange->declare(); $queue = new AMQPQueue($channel); $queue->setName($queueName); $queue->declare(); $queue->bind($exchangeName, $routingKey); $exchange->publish($message, $routingKey); Consumer: <?php $queueName = 'testQueue'; $connection = new AMQPConnection(); $connection->connect(); $channel = new AMQPChannel($connection); $queue = new AMQPQueue($channel); $queue->setName($queueName); $queue->declare(); function processMessage($envelope, $queue) { echo "Message: " . $envelope->getBody() . "\n"; $queue->ack($envelope->getDeliveryTag()); return false; } while(1) { //Consume messages on queue $queue->consume("processMessage"); } Expected result: ---------------- When I run "rabbitmqctl list_consumers" I should only see one consumer and the list should not increase when enqueueing additional messages. Actual result: -------------- The list of the consumers is increasing when running rabbitmqctl list_consumers. Initially this is the list: Listing consumers ... testQueue <rabbit@bogdan.1.22176.153> amq.ctag-EiDv7sVcx8vzElRwhRfKeA== true ...done. After 3 messages enqueued, this is the list: Listing consumers ... testQueue <rabbit@bogdan.1.22176.153> amq.ctag-lZBoY7kFIk30ZrmCtVtdUg== true testQueue <rabbit@bogdan.1.22176.153> amq.ctag-+DBmbIWmwLiHxuuIHa4hfQ== true testQueue <rabbit@bogdan.1.22176.153> amq.ctag-B2GBuNg8Cw2dBdIvU+IBmg== true testQueue <rabbit@bogdan.1.22176.153> amq.ctag-EiDv7sVcx8vzElRwhRfKeA== true ...done.