Page 1 of 1

popen - premature process death

Posted: Tue May 30, 2006 3:29 pm
by joshuaxls
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm writing a script that needs to call some perl scripts in the same directory as the running PHP script. It looks something like this:

Code: Select all

echo "<p id=\"output\">";
$handle = popen( "perl command.pl $args", "r" );
while( !feof($handle) )
{
echo nl2br(fgets($handle));
}
pclose($handle);
echo "</p>";
Well, this worked somewhat well for a time. Now when I run this, I see about half a second's worth of output from the command, and then the page hangs. Looking at "ps" on the server, I see that there's a DEFUNCT sh process owned by apache (PHP is not running as CGI) that's been zombified. It looks as if the command is getting killed within half a second of being run. Like I said, this just started screwing up all of the sudden -- Unfortunately, I can't remember whether or not I changed any important configuration variables that might have affected this. I'm pretty sure that I haven't.

Any clues? I even get the same problem with passthru().


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 30, 2006 5:12 pm
by Christopher
You might want to try adding the length parameter to fgets() and use output buffering as well.