|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-05-08 05:40 UTC] inqualab1985 at gmail dot com
Description:
------------
Hi! PHP Team
I am facing a problem of apache hang up due to exec() function.
I am using PHP 5.2.5 and Apache 2.2 on MS Window 2000 SP4 & also on MS Window XP.
The problem is that I have to execute a exe, for which I have use
exec(). Normally it works Fine, but sometime (randomly) it hang up. It will lock the apache and if we call the same page or any other page of php having exec(), it hang up at the line where exec() function is used. If we commented the line having exec(), then the page run & loaded correctly.
The problem also become critical because there is no error for this.
Also none of the error handling & logging mechanism works.
The only solution to this problem is to restart the Apache.
I am providing you as much as information as possible to catch the problem correctly.
Reproduce code:
---------------
$exeFilePath = realpath("../sample.exe");
if (eregi("win", PHP_OS))
$command = "\"\"$exeFilePath\" argument1\"";
else
$command = "\"$exeFilePath\" argument1";
$output = null;
$returnVal = null;
$result = exec($command,$output,$returnVal);
if($returnVal !=0)
echo "Error";
else
echo $output[0];
echo "end of the program";
Expected result:
----------------
it will show the output of exe for particular argument.
Actual result:
--------------
Normally it works correctly as expected but sometime the the execution of the page hang at line "$result = exec($command,$output,$returnVal);" . After this has happen I am not able to run any script that will use
the exec(). In all scripts apache hangs at exec() function, do not matter which exe will be called.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
This is happening to me as well, PHP 5.2.8, Apache 2.2.11, Windows 2000 Pro SP4. However, it only seems to happen when PHP is configured as an Apache module (php5apache2_2.dll); when I configure it as CGI, it works fine. I also have anecdotal evidence that it's related somehow to other sockets being open on the system. In my case, we have a VB (compiled) application with an embedded IE control, and also opens the serial port to communicate with some hardware. If that hardware is plugged in (and PHP is loaded as a module), then our scripts hang at 'exec("ping -n 1 somehost")'. If I unplug the hardware (so the serial port can't be opened), it works.I am having the same or similar issue: OS: MS2003 PHP: 5.2.6 APACHE2: 2.2 The bug occurs with an PHP script that has a PHP passthru exec call that hangs every now and then. After the first hang occurs then any passthru call hangs in the same manner. I believe that the passthru call runs as I am calling a sendmail.exe process that does send the E-Mail, however, the Browser page hangs after the E-Mail has been sent by sendmail.exe called via passthru(). There are no PHP or Apache2 errors or warnings. It seems that the problem happens when (2) calls to the same .exe happens at the same time, but, I have no real proof of this, as I can't provide execution times for each instance of the sendmail.exe running. This is a serious problem, as all pages that call an .exe process after the initial hang will hang up as well. I can clear the bug by simply stopping and restarting the Apache service. I also note that If I run the page, that hangs up, manually in a Command Prompt DOS window like: D:\php page.php there are no hangs and the process performs correctly even during and after the first showing of the bug. So the problem seems to be when PHP does an exec call in conjunction with Apache, as I said even during the time a hang occurs I can still exec passthru commands from a command prompt. I can also run any page that calls PHP as long as the page does not have any exec or passthru calls in it, and all pages with HTML only runs fine as well during the hang period.Thanks for looking into my problems with exec() at the latest PHP. Example for actual code, as in application (was running nicely in earlier PHP installations, but not under PHP 2.4 anymore): $str1Name = "C:\Map Maker\MMmacro.exe"; $str2Name = "command=remove layer"; exec(chr(34).$str1Name.chr(34).chr(32).chr(34).$str2Name.chr(34)); I am using a GIS called Map Maker, with powerful MMmacro functions (www.mapmaker.com). 'remove layer' is one of the most basic parameters of MMmacro. A more simple test version also failed: $str1Name = "C:\Windows\Notepad.exe"; exec($str1Name); I also tested, all without success: - with bat file, which then calls notepad.exe - with exe/bat in different folders: document root (C:\xampp\htdocs) or from calling directory (C:\xampp\htdocs\lupmis_s) - with 'start .....' - with popen - with exec( .... < file.in > file.out 2> nul", $output); - with exec(....,$output, $return); - with exec("ping google.com", $output, $return); ------------- My environment: PHP 5.4.4 (VC 9) Apache 2.4.2 Xampp 'default' installation 1.8 on C:\xampp Apache with PHP, MySQL running as services Win 7 Home Premium / 64 bit 4 GB RAM HP Pavilion g7 Notebook Bought in Germany, but OS and all programs installed in English Running as administrator Total application has > 220 PHP programs, with > 250 exec calls. If you give me your full email address, I can also send you the php.ini and httpd.conf. Thanks for any advice GerhardSeen 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