xuman3288 / php-apns

Automatically exported from code.google.com/p/php-apns
0 stars 0 forks source link

Process::kil() not killing service process properly #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. sending a message
2. waiting for the PushMonitor to kill the service process

What is the expected output? What do you see instead?
Expect the service process to be killed, instead app just hangs

What version of the product are you using? On what operating system?
Debian 

Please provide any additional information below.

I suspect the code in process::kill() which seems to have been copied from the 
PHP docs doesn't get the child process IDs from the 
parent PID correctly.

The line :

$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);

makes no sense to me as the preg split should surely be on the output of the 
command 'ps -o pid --no-heading --ppid $ppid' not the 
command line itself.

Is there a reason we need to find child PIDs? From what I can see the 
PushService.php file doesnt open any child processes.

Ive replaced the function with the following code which works for me:

    public function kill()
    {
        global $debug;

        $status = proc_get_status($this->pointer);

        print_r($status);

        if($status['running'])
        {
            if($debug)
                echo 'proc is running...closing pipes.';

            fclose($this->pipes[0]);
            fclose($this->pipes[1]);
            fclose($this->pipes[2]);

            $ppid = $status['pid'];         

            proc_terminate($this->pointer);

            return (proc_close($this->pointer) == 0);
        }
         }

I'm not sure if I need the proc_close condition on return.

Original issue reported on code.google.com by mikey...@gmail.com on 28 Aug 2009 at 11:54

GoogleCodeExporter commented 9 years ago
Actually, that piece of code has always been problematic. In some systems, it 
is working perfectly (as it is in my 
Debian Lenny server); however, some other Debian servers too are having 
problems (and they have solved the 
problem by using --ppid instead of -pid).
The reasons of this are still unknown.

I'm going to try your solution, and see if this makes some things better.

Original comment by alessand...@gmail.com on 31 Aug 2009 at 9:00

GoogleCodeExporter commented 9 years ago
I was experiencing similar issues as mikeytrw on Centos 5.3 server, and wanted 
to confirm if child process 
from the parent(PushMonitor needed killing). It turns out that it's managed 
fine, and you dont need to kill all 
child processes that belong to the parent, since only one happens at a time. 

I stuck in the code fragment before i sent a message to see what child id's 
there are and forced it to fail by 
choosing an invalid server ip for the client.  it found the one child process 
and the ps command to find the 
process.  
                $moo = getmypid(); //get parent pid (PushMonitor.php)
                $pids = preg_split('/\s+/', `ps -F --ppid $moo`); //confirm what ps pulled up
                print_r($pids);

and i guess one modification on mikeytrw's code that i would put is 

replace:
proc_terminate($this->pointer);

with:

                        if(!proc_terminate($this->pointer)){
                          posix_kill($ppid, 9); //if it cannot terminate pointer,kill 9
                        }

i guess just incase it can't terminate for whatever reason, it can still kill 
the process. someone can correct me 
if this is redundant.

Original comment by vincent....@gmail.com on 10 Sep 2009 at 8:28