note 115715 added to function.pcntl-signal
| From: | fx4084 at gmail dot com | Date: | Fri, 12 Sep 2014 08:13:57 +0000 |
| Subject: | note 115715 added to function.pcntl-signal | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200426@lists.php.net to get a copy of this message | ||
<?php
pcntl_signal(SIGTERM, function($signo) {
echo "\n This signal is called. [$signo] \n";
Status::$state = -1;
});
class Status{
public static $state = 0;
}
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
}
if($pid) {
// parent
} else {
while(true) {
// Dispatching...
pcntl_signal_dispatch();
if(Status::$state == -1) {
// Do something and end loop.
break;
}
for($j = 0; $j < 2; $j++) {
echo '.';
sleep(1);
}
echo "\n";
}
echo "Finish \n";
exit();
}
$n = 0;
while(true) {
$res = pcntl_waitpid($pid, $status, WNOHANG);
// If the child process ends, then end the main process.
if(-1 == $res || $res > 0)
break;
// Send a signal after 5 seconds..
if($n == 5)
posix_kill($pid, SIGTERM);
$n++;
sleep(1);
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 202.108.16.78
----
Manual Page -- http://php.net/manual/en/function.pcntl-signal.php
Edit -- https://master.php.net/note/edit/115715
Del: integrated -- https://master.php.net/note/delete/115715/integrated
Del: useless -- https://master.php.net/note/delete/115715/useless
Del: bad code -- https://master.php.net/note/delete/115715/bad+code
Del: spam -- https://master.php.net/note/delete/115715/spam
Del: non-english -- https://master.php.net/note/delete/115715/non-english
Del: in docs -- https://master.php.net/note/delete/115715/in+docs
Del: other reasons-- https://master.php.net/note/delete/115715
Reject -- https://master.php.net/note/reject/115715
Search -- https://master.php.net/manage/user-notes.php