title: How do I catch a UNIX TERM Signal so I can gracefully terminate a PHP process?
body: <p>I'm running many PHP processes via <a href="http://supervisord.org/configuration.html" rel="nofollow">Supervisord</a>. Sometimes I need to shut Supervisord down.  When I do so, I have it send a TERM signal to all the PHP processes it has spawned ( using <code>stopsignal=TERM</code> in supervisord.conf ).</p>
  
  <p>I'd like to intercept that TERM Signal and gracefully terminate the PHP process.  Can this be done?</p>
  
  <p>I've added this code to my PHP program to try and do this:</p>
  
  <pre><code>declare( ticks = 1 );
  function gracefully_terminate() {
      echo "\n\ngracefully terminating\n\n";
  }
  pcntl_signal( SIGTERM, "gracefully_terminate" );
  </code></pre>
  
  <p>Also ... for ease of testing, how do I send a TERM signal to a PHP process via the CLI?  I've tried using <code>Kill -s TERM #####</code> ( ##### is the PID of the PHP process ).  Perhaps this is sending the TERM signal, but it's not terminating the PHP process.</p>