<div dir="ltr">Hi,<div><br></div><div style>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.</div><div style><br></div><div style>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.</div>
<div style><br></div><div style>Regards,</div><div style><br></div><div style>Alvaro</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 23, 2013 at 10:45 PM, Colleen Mirabello <span dir="ltr"><<a href="mailto:colleen@surfmerchants.com" target="_blank">colleen@surfmerchants.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
(PHP 5.33, AMQP protocol 0-9-1, librabbitmq 0.0.1, phpamqp 1.0.9)<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:center;font-style:normal;background-color:rgb(153,153,204);display:inline!important;font-weight:bold;float:none;line-height:normal;text-transform:none;font-size:12px;white-space:normal;font-family:sans-serif;word-spacing:0px"></span><br>
<br>
I'm having trouble figuring out how to gracefully shut down a
blocking PHP consumer.<br>
<br>
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.<br>
<br>
Our preference is to use consume() rather than get() if possible.<br>
<br>
The problem we're having is how to get a signal to the child
processes to get them to stop consuming.<br>
<br>
A very simple example script (with connection info removed):<br>
<br>
<?php<br>
// so we can catch system calls... <br>
declare(ticks=1); <br>
<br>
pcntl_signal(SIGTERM, array('RunControl', 'sysCalls')); <br>
pcntl_signal(SIGHUP, array('RunControl', 'sysCalls')); <br>
pcntl_signal(SIGUSR1, array('RunControl', 'sysCalls')); <br>
<br>
<br>
class RunControl<br>
{<br>
static $alive = true;<br>
<br>
// catch system calls<br>
function sysCalls($signal) <br>
{ <br>
print "Got signal to die\n";<br>
}<br>
}<br>
<br>
function consume($message, $queue)<br>
{<br>
print "Got a message!\n";<br>
$queue->ack($message->getDeliveryTag());<br>
}<br>
<br>
<br>
$connection = new AMQPConnection($connectionInfo);<br>
$connection->connect();<br>
<br>
$channel = new AMQPChannel($connection);<br>
$queue = new AMQPQueue($channel);<br>
<br>
$queue->setName('my_queue');<br>
<br>
$queue->consume('consume');<br>
?><br>
<br>
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.<br>
<br>
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.<br>
<br>
I tried the workaround described here: <a href="http://blog.andrewrose.co.uk/2008/02/php-getting-signals-through-to-blocking.html" target="_blank">http://blog.andrewrose.co.uk/2008/02/php-getting-signals-through-to-blocking.html</a>
and it resulted in a whole bunch of "interrupted system call"
exceptions.<br>
<br>
Does anyone have any suggestions for how I can get my consumer to
exit gracefully? Thanks.<span class="HOEnZb"><font color="#888888"><br>
<br>
- Colleen<br>
<br>
<br>
</font></span></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>