2018-04-15 16:41:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace NoccyLabs\Ipc\Signal;
|
|
|
|
|
|
|
|
|
|
|
|
class Signal
|
|
|
|
{
|
|
|
|
private $signo;
|
|
|
|
|
2018-04-15 22:08:19 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param integer $signo
|
|
|
|
*/
|
2018-04-15 16:41:46 +02:00
|
|
|
public function __construct(int $signo)
|
|
|
|
{
|
|
|
|
$this->signo = $signo;
|
|
|
|
}
|
|
|
|
|
2018-04-15 22:08:19 +02:00
|
|
|
/**
|
|
|
|
* Set a signal handler, overwriting any previous handler
|
|
|
|
*
|
|
|
|
* @param callable $handler
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-04-15 16:41:46 +02:00
|
|
|
public function setHandler(callable $handler):void
|
|
|
|
{
|
|
|
|
pcntl_signal($this->signo, $handler);
|
|
|
|
}
|
|
|
|
|
2018-04-15 22:08:19 +02:00
|
|
|
/**
|
|
|
|
* Dispatch the signal to the specified pid. Default is own pid
|
|
|
|
*
|
|
|
|
* @param int $pid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function dispatch(int $pid=null):bool
|
2018-04-15 16:41:46 +02:00
|
|
|
{
|
2018-04-15 17:25:55 +02:00
|
|
|
return posix_kill($pid?:posix_getpid(), $this->signo);
|
2018-04-15 16:41:46 +02:00
|
|
|
}
|
|
|
|
}
|