[rabbitmq-discuss] Graceful shutdown of blocking consumers in PHP?
videlalvaro at gmail.com
Thu May 23 22:41:28 BST 2013
Using that library, can you consume from more than one queue? If yes, then
you could send control messages to the script and make it stop.
With php-amqplib since the while loop is part of user land code, you can
control all the consuming parts on your own so this wouldn't be a problem.
On Thu, May 23, 2013 at 10:45 PM, Colleen Mirabello <
colleen at surfmerchants.com> wrote:
> (PHP 5.33, AMQP protocol 0-9-1, librabbitmq 0.0.1, phpamqp 1.0.9)
> I'm having trouble figuring out how to gracefully shut down a blocking PHP
> The context of this problem is that we would like to create a script that
> forks many consumer children based on a configuration file. That script
> will then monitor its children and restart them should any fail. We would
> also like to be able to kill this parent script and have it stop and kill
> its children and then exit.
> Our preference is to use consume() rather than get() if possible.
> The problem we're having is how to get a signal to the child processes to
> get them to stop consuming.
> A very simple example script (with connection info removed):
> // so we can catch system calls...
> pcntl_signal(SIGTERM, array('RunControl', 'sysCalls'));
> pcntl_signal(SIGHUP, array('RunControl', 'sysCalls'));
> pcntl_signal(SIGUSR1, array('RunControl', 'sysCalls'));
> class RunControl
> static $alive = true;
> // catch system calls
> function sysCalls($signal)
> print "Got signal to die\n";
> function consume($message, $queue)
> print "Got a message!\n";
> $connection = new AMQPConnection($connectionInfo);
> $channel = new AMQPChannel($connection);
> $queue = new AMQPQueue($channel);
> If I run this script, the consumer will happily consume messages. However,
> executing a kill command on its pid does not cause the "Got signal to die"
> message to print.
> I have tried using $queue->cancel() in many different configurations
> (within the same script, in another script, with a consumer tag, without),
> but it doesn't seem to do anything.
> I tried the workaround described here:
> and it resulted in a whole bunch of "interrupted system call" exceptions.
> Does anyone have any suggestions for how I can get my consumer to exit
> gracefully? Thanks.
> - Colleen
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss