I was having some issues with processing a signal using an object method I use for something else as well. In particular, I wanted to handle SIGCHLD with my own method "do_reap()" which I also call after a stream_select timeout and that uses a non-blocking pcntl_waitpid function.
The method was called when the signal was received but it couldn't reap the child.
The only way it worked was by creating a new handler that itself called do_reap().
So in other words, the following does not work:
class Parent {
/* ... */
private function do_reap(){
$p = pcntl_waitpid(-1,$status,WNOHANG);
if($p > 0){
echo "\nReaped zombie child " . $p;
}
public function run(){
/* ... */
pcntl_signal(SIGCHLD,array(&$this,"do_reap"));
$readable = @stream_select($read,$null,$null,5); // 5 sec timeout
if($readable === 0){
// we got a timeout
$this->do_reap();
}
}
But this work:
class Parent {
/* ... */
private function do_reap(){
$p = pcntl_waitpid(-1,$status,WNOHANG);
if($p > 0){
echo "\nReaped zombie child " . $p;
}
public function run(){
/* ... */
pcntl_signal(SIGCHLD,array(&$this,"child_died"));
$readable = @stream_select($read,$null,$null,5); // 5 sec timeout
if($readable === 0){
// we got a timeout
$this->do_reap();
}
private function child_died(){
$this->do_reap();
}
}
----
Server IP: 66.207.199.35
Probable Submitter: 209.202.82.139
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-signal.php
Edit -- https://master.php.net/note/edit/102765
Del: integrated -- https://master.php.net/note/delete/102765/integrated
Del: useless -- https://master.php.net/note/delete/102765/useless
Del: bad code -- https://master.php.net/note/delete/102765/bad+code
Del: spam -- https://master.php.net/note/delete/102765/spam
Del: non-english -- https://master.php.net/note/delete/102765/non-english
Del: in docs -- https://master.php.net/note/delete/102765/in+docs
Del: other reasons-- https://master.php.net/note/delete/102765
Reject -- https://master.php.net/note/reject/102765
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.