|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-12-30 15:52 UTC] nlopess@php.net
Description:
------------
With the short reproduce code below, PHP fork()s a new process (sh), that itself forks a new one (php). proc_terminate() kill()s the sh process, but the php one doesn't get killed.
I'm not really sure what is causing this problem, but it is breaking run-tests.php on timeout.
Reproduce code:
---------------
<?php
$cmd='php -r "while(1){}" 2>&1';
$proc = proc_open($cmd, array(), $pipes);
var_dump(proc_terminate($proc));
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 04:00:01 2025 UTC |
An easy workaround... Instead of: $proc = proc_open('cat', ...); Use this: $proc = proc_open('exec cat', ...); It tells the shell to replace its own process with the command being executed rather than forking a child process. This way you can properly kill the command using proc_terminate($proc).I believe this should be addressed in PHP 7.4 by writing: $proc = proc_open( ['php', '-r', 'while(1){}'], [2 => ['redirect', 1]], $pipes); var_dump(proc_terminate($proc)); This will not go through a shell, and as such the created process will be terminated directly. Please let me know if there are still issues when going through the shell-free interface.