note 110945 added to amqpqueue.consume
| From: | pinepain at gmail dot com | Date: | Thu, 27 Dec 2012 18:00:22 +0000 |
| Subject: | note 110945 added to amqpqueue.consume | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192690@lists.php.net to get a copy of this message | ||
Be careful using this function with non-zero amqp.timeout (you may check at
AMQPConnection::getTimeout), because it looks like timeout value says how long to wait for a new
message from broker before die in way like
Fatal error: Uncaught exception 'AMQPConnectionException' with message 'Resource
temporarily unavailable' in /path/to/your/file.php:12
Stack trace:
#0 /path/to/your/file.php(12): AMQPQueue->consume(Object(Closure), 128)
#1 {main}
thrown in /path/to/your/file.php on line 12
As for notes about blocking, system resources greediness and so and so, you can investigate how it
works by looking in amqp_queue.c for read_message_from_channel C function declaration and
PHP_METHOD(amqp_queue_class, consume) method declaration. For me it works perfectly without any
uncommon resources usage or I/O performance degradation under the load of 10k 64b message per second
with delivery time for less than 0.001 sec.
OS: FreeBSD *** 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Sat Mar ****** 2011 root@*****:**** amd64
PHP: PHP Version => 5.3.10, Suhosin Patch 0.9.10, Zend Engine v2.3.0
php AMQP extnsion:
amqp
Version => 1.0.9
Revision => $Revision: 327551 $
Compiled => Dec 2* 2012 @ *****
AMQP protocol version => 0-9-1
librabbitmq version => 0.2.0
Directive => Local Value => Master Value
amqp.auto_ack => 0 => 0
amqp.host => localhost => localhost
amqp.login => guest => guest
amqp.password => guest => guest
amqp.port => 5672 => 5672
amqp.prefetch_count => 3 => 3
amqp.timeout => 0 => 0
amqp.vhost => / => /
AMQP broker: RabbitMQ 3.0.1, Erlang R14B04
Definitely, such loop will block main thread, but due to single-thread PHP nature it's
completely normal behavior. To exit this consumption loop your callback function or method (i prefer
to use closures, btw) should return FALSE.
The benefit of this function is that you don't have manually iteration for all messages, and
what is more important, if there is no unprocessed messages in queue it will wait for such for you.
So you have just to run you consumer (one or many) and optionally time to time check whether they
still alive just for reason if you are not sure about callbacks or memory-limit-critical stuff
----
Server IP: 69.147.83.199
Probable Submitter: 92.244.100.226
----
Manual Page -- http://php.net/manual/en/amqpqueue.consume.php
Edit -- https://master.php.net/note/edit/110945
Del: integrated -- https://master.php.net/note/delete/110945/integrated
Del: useless -- https://master.php.net/note/delete/110945/useless
Del: bad code -- https://master.php.net/note/delete/110945/bad+code
Del: spam -- https://master.php.net/note/delete/110945/spam
Del: non-english -- https://master.php.net/note/delete/110945/non-english
Del: in docs -- https://master.php.net/note/delete/110945/in+docs
Del: other reasons-- https://master.php.net/note/delete/110945
Reject -- https://master.php.net/note/reject/110945
Search -- https://master.php.net/manage/user-notes.php