假设我们必须创建交换和队列。第一个脚本将使用 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?