note 113918 added to function.proc-terminate

From: Date: Tue, 17 Dec 2013 15:47:41 +0000
Subject: note 113918 added to function.proc-terminate
Groups: php.notes 
Request: Send a blank email to php-notes+get-197960@lists.php.net to get a copy of this message
on Windows platform proc_terminate() does not kill sub-processes that are not handling kill signals. It happens even if you call xxx.exe and call proc_terminate() the process will remain active. The solution is instead of calling proc_terminate() is to call the user-defined kill() function (already win/unix optimized) After that need to close all pipes and execute proc_close(). function kill($pid){ return stripos(php_uname('s'), 'win')>-1 ? exec("taskkill /F /T /PID $pid") : exec("kill -9 $pid"); } function killall($pids) { $os=stripos(php_uname('s'), 'win')>-1; ($_=implode($os?' /PID ':' ',$pids)) or ($_=$pids); return preg_match('/success|close/', $os ? exec("taskkill /F /T /PID $_") : exec("kill -9 $_")); } Example: $pstatus = proc_get_status($resource); $PID = $pstatus['pid']; // other commands kill($PID); // instead of proc_terminate($resource); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($resource); ---- Server IP: 192.41.45.150 Probable Submitter: 148.198.43.5 ---- Manual Page -- http://php.net/manual/en/function.proc-terminate.php Edit -- https://master.php.net/note/edit/113918 Del: integrated -- https://master.php.net/note/delete/113918/integrated Del: useless -- https://master.php.net/note/delete/113918/useless Del: bad code -- https://master.php.net/note/delete/113918/bad+code Del: spam -- https://master.php.net/note/delete/113918/spam Del: non-english -- https://master.php.net/note/delete/113918/non-english Del: in docs -- https://master.php.net/note/delete/113918/in+docs Del: other reasons-- https://master.php.net/note/delete/113918 Reject -- https://master.php.net/note/reject/113918 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197960) next »