php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33296 popen (passthru etc.) doesn't work correct
Submitted: 2005-06-10 10:54 UTC Modified: 2005-06-23 01:00 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: thomas dot wetzler at siemens dot com Assigned:
Status: No Feedback Package: Program Execution
PHP Version: 4.3.10 OS: SUN OS
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
36 - 33 = ?
Subscribe to this entry?

 
 [2005-06-10 10:54 UTC] thomas dot wetzler at siemens dot com
Description:
------------
While sequentially opening and closing several processes via popen (or passthru, exec and '' command) php looses some processes. This takes place if, for instance, the user presses the reload-button on a website several times. 

With the coding below, you can reproduce the failure (takes place on commandline (php.exe) and in apache module (mod_php)).

Reproduce code:
---------------
#!/wir/webadmin/share/php4/bin/php
#
<?
for ($i=0; $i<900; $i++) {
   $statement = "ls -l";
   echo "\n\n$i***************************\n";
	$handle = popen($statement, 'r');
	echo "Subprozess: '$handle'; " . gettype($handle) . "\n";
	 while (!feof($handle)) 
	 {
  		echo fread($handle, 8192);
	 }
	pclose($handle);
}
?>

programcall: <progname> > <resultfile>

Expected result:
----------------
Within the result-file, there should be 900 times the same result from the system command (here ls -l command). 


255***************************
Subprozess: 'Resource id #259'; resource
total 2526
-rw-r--r--   1 webadmin oracle    572135 Jun 10 09:52 _test1.txt
drwxr-xr-x   2 wir      oracle        96 May  2 15:27 mail
-rw-r--r--   1 wir      oracle    258956 Jun 10 10:42 test
-rwxrwx---   1 wir      oracle       698 Jun 10 10:41 test.php
-rw-r--r--   1 webadmin oracle    105326 Jun 10 09:52 test1
-rwxrwx---   1 wir      oracle       656 Jun 10 09:48 test1.php
-rwxr-x---   1 wir      oracle       321 Jun 10 10:43 thomas.php
-rw-r--r--   1 wir      oracle    148274 Jun 10 10:43 thw.txt



Actual result:
--------------
Some results are missing. The same programm written in perl or shellscript is working correct. 

-rwxr-x---   1 wir      oracle       321 Jun 10 10:43 thomas.php
-rw-r--r--   1 wir      oracle    148274 Jun 10 10:43 thw.txt


256***************************
Subprozess: 'Resource id #260'; resource


257***************************
Subprozess: 'Resource id #261'; resource
total 2526
-rw-r--r--   1 webadmin oracle    572135 Jun 10 09:52 _test1.txt
drwxr-xr-x   2 wir      oracle        96 May  

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-11 15:18 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-06-15 15:54 UTC] thomas dot wetzler at siemens dot com
We tried out PHP Version 5. With the commandline (php.exe) it seems to work but with the mod_php-module we get the same failure. 

Because the testing of our application take a long time, it would be good if you can find a solution for Version 4.
 [2005-06-15 19:16 UTC] sniper@php.net
Please try using this CVS snapshot:

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

Try also the latest PHP 4 snapshot.

 [2005-06-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-07-19 09:47 UTC] screen at brainkrash dot com
Tested script from <thomas dot wetzler at siemens dot com> on php4.4.0 cli/apache2 and php4-STABLE-200507190640 on Linux server and ALL samples worked. 

Found this bug searching for a similar (maybe the same) issue related to popen/freads calling SVN. I modified this test script and ran tests using 4.4.0 and php4-STABLE-200507190640 with the following results:

script
------
#!/usr/local/apache2/php/bin/php
#
<?
for ($i=0; $i<10; $i++) {
	$statement = "/usr/local/subversion/bin/svn help";
	echo "\n\n$i***************************\n";
	$handle = popen($statement, 'r');
	echo "Subprozess: '$handle'; " . gettype($handle) . "\n";
	
	$output = '';
	while (!feof($handle)) {
		$output .= fgets($handle);
	}
	echo $output;
	
	pclose($handle);
}
?>


results
-------
/usr/local/apache2/php/bin/php -f test.php > test440_cli.txt

	> works

wget -O test440_apache2.txt http://brainkrash.com/~screen/test/test.php

	> all 10 fail with no return from fgets
	
/usr/local/apache2/php/bin/php -f test.php > test4-200507190640_cli.txt

	> works

wget -O test4-200507190640_apache2.txt http://brainkrash.com/~screen/test/test.php

	> all 10 fail with no return from fgets


expected result
---------------
0***************************
Subprozess: 'Resource id #4'; resource
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.2.1.
Type 'svn help <subcommand>' for help on a specific subcommand.

Most subcommands take file and/or directory arguments, recursing
on the directories.  If no arguments are supplied to such a
command, it recurses on the current directory (inclusive) by default.

Available subcommands:
   add
   blame (praise, annotate, ann)
... <TRUNCATED>


failure results
---------------
0***************************
Subprozess: 'Resource id #2'; resource


<EOF>
 [2007-09-17 08:39 UTC] uj at u dot g8tr
http://www.meta-fx.com
 [2007-09-24 11:27 UTC] jgh at fgdh dot jfhk
http://www.meta-fx.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC