Hello,
I'm having a problem with some scripts that use the exec (...) function under Windows NT 4.0.
I've got an app that calls some external command line-based applications that return some data through STDOUT, which I process and output to the browser.
When only one request for my script is being served at a time, everything runs fine.
However, if an external command is executing and my webserver tries to handle another request for a PHP script, my server machine freezes. Task manager freezes, I can't access the start menu, but I can still move the mouse. If I have a program open it runs until I give it input (e.g. if a song is playing in Winamp it will play until I hit the "next track" button, then it will freeze). Pressing Ctrl-Alt-Delete clears the screen of everything except my wallpaper and the system goes down completely. The only thing that I can do at this point is a hard reboot of the server. Nothing in either my webserver (Apache) error log or my WinNT application or system logs gives any clue as to what went wrong.
Basically here is the problem step-by-step:
1) Web server is idle
2) A request comes in for my script "ext.php", which calls an external app
3) While exec () is running the program (I can see the program running in task manager), another request comes into the server (for any php page)
4) The server freezes immediately
Alternatively:
1) Web server is idle
2) A request comes in for some script that takes several seconds to execute
3) A request comes in for the script "ext.php", which calls an external app
4) The second request exec () starts
5) The server freezes immediately
My script "ext.php" runs one of the following apps:
- CQPerl (a hacked version of perl) that runs a short script to perform some data retrieval using a proprietary database API)
- Continuus CM (command-line interface to change management software)
- Expect (the tcl-based scripting language) - used to automate a telnet session that gets some data from a remote server
I have also reproduced the problem using the following script:
<?php
exec ("dir c: /s", $output);
foreach ($output as $value)
{
echo "$value<br>";
}
?>
The script above needs to run concurrently with some other script. In my case I opened up 3 browser windows and put the url to that script in each one, hit go and a few seconds later my machine was frozen. This only works if you have a FAT filesystem though (with NTFS the execution of the "dir" command is so fast that the webserver will probably execute the scripts sequentially and not concurrently and therefore the problem does not occur).
I've seen this problem on 2 PC's so far, using the following configurations:
PC #1: Pentium III-700MHz, 768 MB RAM, Windows NT Server 4.0 SP5:
Tried Apache 1.3.27 / PHP 4.2.1 and IIS 4.0 / PHP 4.2.1
PC #2: Pentium III-500MHz, 128 MB RAM, Windows NT Workstation 4.0 SP5:
Tried Apache 1.3.27 / PHP 4.2.1 and Apache 1.3.27 / PHP 4.3.1.
I've also tried every program execution function that returns output that I can think of (exec ($command, $output), exec (getenv ("comspec") . "/C" . $command, $output), shell_exec (...), popen (...) etc.)... each of them results in the same behaviour.
Does anyone have any idea of what is going on here, and how I might go about fixing it?