php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32838 child processes opened with proc_open freeze the script
Submitted: 2005-04-26 14:31 UTC Modified: 2005-05-11 11:09 UTC
From: mjpph at stardust dot fi Assigned:
Status: Closed Package: Program Execution
PHP Version: 5.0.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
4 + 18 = ?
Subscribe to this entry?

 
 [2005-04-26 14:31 UTC] mjpph at stardust dot fi
Description:
------------
I've created three scripts during some time, which of the latest is under PHP 5.0.4. It opens hlds or srcds process as a child process using proc_open. Every pipe is made non-blocking also there are no infinite loops except the one that selects the child process's stdout pipe.

The script reads and runs succesfully for some time, then it suddenly freezes. All buffering is turned off that can be turned off, I also added some DEBUG printouts in the code and it even once freezed in the middle of a single print. The same thing happens with pty and pipe support. Everything has been checked out dozens of times. Both the child process's stdout and stderr pipes are selected and read constantly.

If the child process is terminated from a shell with a kill command the php script suddenly exits without any error or warning message even though it should keep looping the child process, which it normally does if it doesn't freeze.

This behaviour is only happening with hlds and srcds child processes. I've run thousands of execution times of hltv's witht the same script and it has never freezed. Srcds and hlds processes output a lot more data though.

The child process actually continues to run without any problems even if the proc_open is done without pipes and the script has frozen. Obviously the php script as a control script becomes completely useless after this.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-26 15:21 UTC] mjpph at stardust dot fi
It also seems that by using only on fgets() per select to get the child process's output seems to make the script a lot more stable than for example getting the whole buffer with stream_get_contents or by loopin fgets/stream_get_line. This was also the case with the earlier script though it didn't make the script still completely stable.
 [2005-04-27 12:42 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-04-28 00:10 UTC] wez@php.net
Also specify which SAPI you are using: eg: Apache, CLI, CGI.
Note that launching a CGI child process from either Apache or an existing CGI process is going to bite you unless you clean up the environmental variables you pass on to the child process.
 [2005-05-02 18:10 UTC] mjpph at stardust dot fi
I'm using PHP's CLI version. Also I noticed that when I upgraded an earlier 5.x PHP to 5.0.4 it started to freeze one process runner which has always worked perfectly. The script was unchanged.

Test code can be anything that just simply opens a child process which has atleast relatively high output and keeps listening to it for a long time (several hours, days). I'll add two simple test scripts asap.
 [2005-05-05 15:16 UTC] mjpph at stardust dot fi
More info. I have a identical script running on a machine with PHP 5.0.0RC3, it has no problems mentioned here. All scripts run perfectly well. When I run the identical script on 5.0.4 it freezes after some time of runtime almost without exceptions. Both are CLI versions compiled from the source. The hltv-runner started to freeze after I upgraded PHP from 5.0.0RC3 to 5.0.4, it never did before the upgrade.
 [2005-05-06 03:21 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-05-06 09:07 UTC] mjpph at stardust dot fi
Ok I'll try that snapshot. One thing I notice too, all version seem to have PTY support of the proc_open disabled. It can be easily seen by checking ext/standard/proc_open.c which has two pty-related defines which start by "0 &&". I changed these and got fully working proc_open PTY support on my system. This didn't have any effect on the freezing problem though. Maybe the PTY support is still buggy or someone has tested something and forgot to enable it? Just as a sidenote.
 [2005-05-08 16:34 UTC] mjpph at stardust dot fi
It looks like the newest snapshot has fixed the issue. I've been now running the scripts for 55 hours without one single failure. Before this atleast one, most likely half of the scripts would have freezed already. I'll send some more feedback after few more days of testing.
 [2005-05-11 10:02 UTC] tony2001@php.net
Are you still able to reproduce it?
 [2005-05-11 10:08 UTC] mjpph at stardust dot fi
It seems the snapshot sniper posted has solved the bug. I usually was able to freeze atleast one script in say 48 hours with almost 100% propability. Usually more than one script. This time around, with the sniper's snapshot, the scripts have been running for over 120 hours without a single failure.

I think it's safe to say this bug has been solved. Thanks a lot, I wrestled with this bug for a long time.
 [2005-05-11 11:09 UTC] tony2001@php.net
Ok, marking as closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 04:01:30 2024 UTC