With AzaThread you can handle POSIX signals in the parent and the child processes. In the child process all available signals are always listened. In parent, this is done only when the option $listenMasterSignals
is enabled (by default).
To handle signal it's enough to declare a method that will be called when it is received. For the child process method name is the name of the signal (case insensitive). The first argument of this method will be the number - the signal code.
class ExampleThread extends Thread
{
function process()
{
// ...
}
/**
* SIGUSR1 handler for the child process
*
* @param int $signo
*/
protected function sigUsr1($signo)
{
// ...
}
}
All the same for the parent process, only the method must be static and prefixed with "m".
class ExampleThread extends Thread
{
function process()
{
// ...
}
/**
* SIGUSR2 handler for the parent process
*
* @param int $signo
*/
protected static function mSigUsr2($signo)
{
// ...
}
}
Send signals is as simple as receiving. To do this, there are two public methods: sendSignalToParent
, sendSignalToChild
. Which send a signal to the parent and child process respectively.
$thread->sendSignalToChild(SIGUSR1);
$this->sendSignalToParent(SIGUSR2);