<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&#39;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">&lt;<a href="mailto:colleen@surfmerchants.com" target="_blank">colleen@surfmerchants.com</a>&gt;</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&#39;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&#39;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>
    &lt;?php<br>
    // so we can catch system calls... <br>
    declare(ticks=1); <br>
    �<br>
    pcntl_signal(SIGTERM, array(&#39;RunControl&#39;, &#39;sysCalls&#39;)); <br>
    pcntl_signal(SIGHUP, array(&#39;RunControl&#39;, &#39;sysCalls&#39;)); <br>
    pcntl_signal(SIGUSR1, array(&#39;RunControl&#39;, &#39;sysCalls&#39;)); <br>
    <br>
    <br>
    class RunControl<br>
    {<br>
    ��� static $alive = true;<br>
    <br>
    ��� // catch system calls<br>
    ��� function sysCalls($signal) <br>
    ��� { <br>
    ��� ��� print &quot;Got signal to die\n&quot;;<br>
    ��� }<br>
    }<br>
    <br>
    function consume($message, $queue)<br>
    {<br>
    ��� print &quot;Got a message!\n&quot;;<br>
    ��� $queue-&gt;ack($message-&gt;getDeliveryTag());<br>
    }<br>
    <br>
    <br>
    $connection = new AMQPConnection($connectionInfo);<br>
    $connection-&gt;connect();<br>
    <br>
    $channel = new AMQPChannel($connection);<br>
    $queue = new AMQPQueue($channel);<br>
    <br>
    $queue-&gt;setName(&#39;my_queue&#39;);<br>
    <br>
    $queue-&gt;consume(&#39;consume&#39;);<br>
    ?&gt;<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 &quot;Got
    signal to die&quot; message to print.<br>
    <br>
    I have tried using $queue-&gt;cancel() in many different
    configurations (within the same script, in another script, with a
    consumer tag, without), but it doesn&#39;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 &quot;interrupted system call&quot;
    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>