|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2011-10-26 15:24 UTC] steven_wright at mcafee dot com
 Description:
------------
amqp    0.3.1   beta
I have a script that runs a loop 10,000 times. In the loop I publish two messages. 
There are two consumers waiting in a while loop that get the messages using 
consume(). 
The script consumes about 10GB of RAM.
I am concerned about the amount of memory being used. 
The code that I pasted below should be placed into two separate files. Each one is 
run from the console. Start the consumer first.
Test script:
---------------
$cnnConfig = array("exchange" => "test-topic", "queue" => "test-queue", "hostname" => "localhost", "options" => array("type" => "topic", "autoDelete" => true));
$cnn = new AMQPConnection($cnnConfig);
$cnn->connect();
$logQ = new AMQPQueue($cnn);
$logQ->declare('log');
$logQ->bind($cnnConfig['exchange'], 'log');
$options = array('min' => 1,'max' => 10,'ack' => true);
while (true){$msg = $logQ->consume($options); var_dump($msg[0]['message_body']); }
// Producer code
$cnnConfig = array("exchange" => "test-topic", "queue" => "test-queue", "hostname" => "localhost", "options" => array("type" => "topic", "autoDelete" => true));
$cnn = new AMQPConnection($cnnConfig);
$cnn->connect();
$ex = new AMQPExchange($cnn, $cnnConfig['exchange']);
$ex->declare($cnnConfig['exchange'], $cnnConfig['options']['type'], $cnnConfig['options']['autoDelete']);
for ($i = 0; $i < 10000; $i++){
    $ex->publish('Message '.$i.' goes to test.log: ' . date("h:i:s"), 'log');
}
Expected result:
----------------
I expect that the script will echo the message 10,000 times.
string(36) "Message 0 goes to test.log: 11:19:04"
string(36) "Message 1 goes to test.log: 11:19:04"
string(37) "Message 2 goes to test.log: 11:19:04"
And so on.
Actual result:
--------------
[swright@vm1-centos5 rabbitmq]$ php rabbit-cons.php
string(36) "Message 0 goes to test.log: 11:19:04"
string(36) "Message 1 goes to test.log: 11:19:04"
string(37) "Message 11 goes to test.log: 11:19:04"
Killed
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 10:00:02 2025 UTC | 
There seems to be a problem with consume() method, when there is a lot o messages in a queue. Example: consumer.php <?php include('config.php'); $amqp = new AMQPConnection($cfg['amqp']); $amqp->connect(); $amqp_ex = new AMQPExchange($amqp); $amqp_ex->declare($cfg['amqp']['exchange'],AMQP_EX_TYPE_TOPIC,AMQP_DURABLE); $amqp_qu = new AMQPQueue($amqp); $amqp_qu->declare($cfg['amqp']['queue'],AMQP_DURABLE); $amqp_qu->bind($cfg['amqp']['exchange'],'slave.#'); $i = 0; while(true) { $msgs = $amqp_qu->consume(array( 'min' => 0, 'max' => 10, 'ack' => false )); foreach($msgs as $msg) $amqp_qu->ack($msg['delivery_tag']); if (!count($msgs)) exit; } send.php - send 1000 messages root@loc:~/php-amqp-bugs# php -f send.php root@loc:~/php-amqp-bugs# /usr/bin/time -f "%P %M" php -f consumer.php 74% 1704880 That's 1704880 KB of RSS mem.