|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61603 Memory Leak in Queue Get
Submitted: 2012-04-02 21:31 UTC Modified: 2012-05-23 21:15 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:0 (0.0%)
From: hyallred at gmail dot com Assigned: pdezwart (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.10 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: hyallred at gmail dot com
New email:
PHP Version: OS:


 [2012-04-02 21:31 UTC] hyallred at gmail dot com
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:


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
// 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.


amqp_queue.c.patch (last revision 2012-04-18 13:31 UTC by zircote at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-09 11:44 UTC] hyallred at gmail dot com
Im getting the same result with the same version of AMQP.

[test@amqp ~]$ php test.php 
 [2012-05-21 19:27 UTC] 66ton99 at gmail dot com
I is fixed in v1.0.3
 [2012-05-23 21:15 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: pdezwart
 [2012-05-23 21:15 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed May 31 01:03:40 2023 UTC