note 96745 added to function.proc-terminate

From: Date: Sat, 13 Mar 2010 19:29:45 +0000
Subject: note 96745 added to function.proc-terminate
Groups: php.notes 
Request: Send a blank email to php-notes+get-167005@lists.php.net to get a copy of this message
Method described in the previous note will not work if your child process has his own childs. There is easier way to solve the problem with non-finishing child processes: <?php $descriptorspec = array( 0 => array('pipe', 'r'), // stdin is a pipe that the child will read from 1 => array('pipe', 'w'), // stdout is a pipe that the child will write to 2 => array('pipe', 'w') // stderr is a pipe the child will write to ); $proc = proc_open('bad_program', $descriptorspec, $pipes); if(!is_resource($proc)) { throw new Exception('bad_program could not be started.'); } // Get current PID $status = proc_get_status($proc); $pid = $status['pid']; // Set process group for the bunch of processes (for easy killing) posix_setpgid($pid, $pid); // Some actions // It's time to kill // Close pipes fclose($pipe[0]); fclose($pipe[1]); fclose($pipe[2]); // Send SIGKILL to all processes within group posix_kill(-$pid, 9); // Close original process proc_close($proc); ?> ---- Server IP: 78.41.111.4 Probable Submitter: 92.242.81.237 ---- Manual Page -- http://www.php.net/manual/en/function.proc-terminate.php Edit -- https://master.php.net/note/edit/96745 Del: integrated -- https://master.php.net/note/delete/96745/integrated Del: useless -- https://master.php.net/note/delete/96745/useless Del: bad code -- https://master.php.net/note/delete/96745/bad+code Del: spam -- https://master.php.net/note/delete/96745/spam Del: non-english -- https://master.php.net/note/delete/96745/non-english Del: in docs -- https://master.php.net/note/delete/96745/in+docs Del: other reasons-- https://master.php.net/note/delete/96745 Reject -- https://master.php.net/note/reject/96745 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167005) next »