note 98450 added to function.pcntl-wait
| From: | gaylord at 100days dot de | Date: | Wed, 16 Jun 2010 12:17:12 +0000 |
| Subject: | note 98450 added to function.pcntl-wait | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170174@lists.php.net to get a copy of this message | ||
pcntl_wait will not terminate on signals if you have a PHP signal handler activated (pcntl_signal).
This is unless the signal handler was activated with 3rd parameter=true.
Example:
<?php
declare(ticks=1);
pcntl_signal(SIGTERM, "myHandler");
$pid=pcntl_wait($status);
?>
This will not terminate on SIGTERM sent to the process, because "wait" will be restarted
after php recieves the signal. The signal handler "myHandler" will not be called unless
pcntl_wait terminates for some other reason.
Change to:
<?php
declare(ticks=1);
pcntl_signal(SIGTERM, "myHandler", true);
$pid=pcntl_wait($status);
?>
Now the pcntl_wait terminates when a signal comes in and "myHandler" will be called on
SIGTERM. (Make sure to put the wait in a loop though, because it will now not only terminate when a
child exits but also when a signal arrives. Test for $pid>0 to detect a exit message from a
child)
(thanks to Andrey for helping me debugging this)
----
Server IP: 85.214.154.209
Probable Submitter: 87.193.204.81
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-wait.php
Edit -- https://master.php.net/note/edit/98450
Del: integrated -- https://master.php.net/note/delete/98450/integrated
Del: useless -- https://master.php.net/note/delete/98450/useless
Del: bad code -- https://master.php.net/note/delete/98450/bad+code
Del: spam -- https://master.php.net/note/delete/98450/spam
Del: non-english -- https://master.php.net/note/delete/98450/non-english
Del: in docs -- https://master.php.net/note/delete/98450/in+docs
Del: other reasons-- https://master.php.net/note/delete/98450
Reject -- https://master.php.net/note/reject/98450
Search -- https://master.php.net/manage/user-notes.php