|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesamqp_queue.c.patch (last revision 2012-04-18 13:31 UTC by zircote at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-05-09 11:44 UTC] hyallred at gmail dot com
[2012-05-21 19:27 UTC] 66ton99 at gmail dot com
[2012-05-23 21:15 UTC] pdezwart@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: pdezwart
[2012-05-23 21:15 UTC] pdezwart@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 19:00:01 2025 UTC |
Description: ------------ There is a memory leak when using the get method on a queue in a while loop when there are no messages in the queue. I was using version 1.0.1 of the amqp extension. There is a simple fix for this that I found. Before line 207 in amqp_queue.c where it returns AMQP_READ_NO_MESSAGES, release the memory allocated for the envelopeZval with: "zval_dtor(envelopeZval);" This should fix the leak when no messages are in queue and prevent the script's memory footprint from growing. Test script: --------------- #!/usr/bin/php -q <?php // This assumes you have an exchange named 'exchange.hello' set up. $connection = new AMQPConnection(); $connection->connect(); $channel = new AMQPChannel($connection); $q = new AMQPQueue($channel); $q->setName('queue.hello'); $q->declare(); $start = time(); while (true) { $msg = $q->get(AMQP_AUTOACK); if (time() - $start > 2) // print out memory usage every 2 secs. { $start = time(); echo memory_get_usage() . "\n"; } } $connection->disconnect(); // disconnect Expected result: ---------------- I expect the memory usage amount to remain constant when no messages are in the queue to process. Actual result: -------------- The memory usage value grows and grows until I run out of memory.