是pecl扩展php-amqp导致内存泄漏?

时间:2012-10-15 13:28:55

标签: php rabbitmq

让我们想象一下,我们必须创建交换和队列。第一个脚本将使用pecl扩展名

pastebin.com/2vzQBjtQ

第二个脚本将使用php-aqmp库http://github.com/videlalvaro/php-amqplib

pastebin.com/WurFfDSE

脚本是相同的,它们只是通过循环声明交换和队列并演示系统内存。

运行第一个脚本,我们得到

php /home/www/application/controllers/rabbit_memory_test.php
100 Memory usage is 23277568
200 Memory usage is 39096320
300 Memory usage is 56262656
400 Memory usage is 74784768
500 Memory usage is 94380032
600 Memory usage is 115019776
700 Memory usage is 135467008
800 Memory usage is 156147712
900 Memory usage is 177041408
It took 2.9051361083984 seconds for php.

运行第二个脚本,我们得到

php /home/www/application/controllers/rabbit_memory_test2.php
100 Memory usage is 9306112
200 Memory usage is 9342976
300 Memory usage is 9342976
400 Memory usage is 9342976
500 Memory usage is 9342976
600 Memory usage is 9342976
700 Memory usage is 9342976
800 Memory usage is 9342976
900 Memory usage is 9342976
1000 Memory usage is 9342976
It took 2.7014260292053 seconds for php.

使用pecl扩展时是否存在内存泄漏,或者我以错误的方式使用扩展api?

1 个答案:

答案 0 :(得分:0)

我解决了问题,将第一个脚本的代码移动到循环的开头

$connection = new AMQPConnection();
$connection->connect();

// Open Channel
$channel    = new AMQPChannel($connection);
$exchange   = new AMQPExchange($channel);
$queue      = new AMQPQueue($channel);