Bug #44942 [Asn->Fbk]: exec() hangs apache

From: Date: Sun, 03 Jul 2016 05:53:41 +0000
Subject: Bug #44942 [Asn->Fbk]: exec() hangs apache
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202008@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=44942&edit=1 ID: 44942 Updated by: pajoye@php.net Reported by: inqualab1985 at gmail dot com Summary: exec() hangs apache -Status: Assigned +Status: Feedback Type: Bug Package: Program Execution Operating System: Windows 2000 SP4 PHP Version: 5.2.5 Assigned To: pajoye Block user comment: N Private report: N New Comment: this should be fixed in latest. Previous Comments: ------------------------------------------------------------------------ [2015-03-24 02:39:42] pajoye@php.net This should be fixed already. Please try latest 5.6 ------------------------------------------------------------------------ [2015-03-23 21:18:13] yardsticks at gmail dot com Same issue here, years later... I built a whole script around the expectation that this would work. The solution posted did not work for me either :( ------------------------------------------------------------------------ [2012-12-06 12:54:57] pajoye@php.net See also #44994 ------------------------------------------------------------------------ [2012-12-05 12:04:02] claudix dot kernel at gmail dot com Seen the same behavior, not only in exec(), but also in similar functions as proc_open/proc_close. When there are concurrent scripts during a same PHP session, the script spawning the process randomly hangs. System: - Windows 2003 server SP2 - Apache 2.2.22/ PHP 5.4.3 I can confirm that calling session_write_close() and then session_start() does the trick. I've observed, though, that the code below doesn't work: $proc = proc_open($cmd,$pipedesc,$pipes); //do stuff with pipes... //... and close pipes session_write_close(); //Close session before hanging function $retval = proc_close($proc); session_start(); //restore session But the code below *does* work: session_write_close(); //Close the session before proc_open() $proc = proc_open($cmd,$pipedesc,$pipes); //do stuff with pipes... //... and close pipes $retval = proc_close($proc); session_start(); //restore session This made me go into the PHP source code (actually the source file "proc_open.c"). I've noticed that the command passed to proc_open() is spawned by calling the WINAPI function CreateProcess(...) with the parameter "bInheritHandles" set to TRUE. As of MSDN documentation, if this parameter is TRUE then all handles are inherited by the child process. It seems that the handle of the session is being inherited by the child process but for some reason the OS doesn't release it when the process ends, eventually yielding a deadlock. The code snippets above show this: the session has to be closed before calling proc_open() to prevent the spawned command from inheriting the session handle. People using exec() cannot see this effect because exec() virtually embeds proc_open/proc_close. May this give a clue to PHP developers? Claudi ------------------------------------------------------------------------ [2012-10-15 15:00:52] mail at GerhardBechtold dot com Pajoye, I didn't find any documentation on the service sensitivity of the new PHP. You might be right, that the eof of the console stream is not taken care properly, but in my case the system is now working (again). ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=44942 -- Edit this bug report at https://bugs.php.net/bug.php?id=44942&edit=1

« previous php.bugs (#202008) next »