php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45922 data is not transmitted throught pipes created by proc_open
Submitted: 2008-08-26 14:31 UTC Modified: 2009-02-20 01:00 UTC
From: TorokAlpar at Gmail dot com Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2CVS-2008-08-27 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: TorokAlpar at Gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-26 14:31 UTC] TorokAlpar at Gmail dot com
Description:
------------
 After starting a program (Written in C) with proc_open the pipes opened seem to be invalid. It looks like no data is transmitted over to the childs stdin, On a read the script blocks.

Please bear with me, this is my firs bug report, and i am debugging this for 7 hours now.

here are my modules: 

 [PHP Modules]
bcmath
calendar
com_dotnet
ctype
date
dom
domxml
exif
filter
ftp
gd
gettext
hash
iconv
imap
json
libxml
mbstring
mcrypt
mime_magic
ming
mssql
mysql
mysqli
odbc
paradox
pcre
pdf
PDO
pdo_mssql
pdo_mysql
ps
Reflection
session
SimpleXML
soap
sockets
SPL
SQLite
standard
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]
Xdebug

Note tha i also tried without Xdebug

Reproduce code:
---------------
$aDescriptorspec = array(
                   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
                   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
                   2 => array("pipe", "w")   // stderr is a file to write to
                );
         $aOptions = array('bypass_shell' => true); // doesn't influence the behavior         
         $rProcess = proc_open('F:\\checkpe-debug2.exe validpe', $aDescriptorspec, $aPipes, null,null, $aOptions);         
         // $aPipes now looks like this:
         // 0 => writeable handle connected to child stdin
         // 1 => readable handle connected to child stdout       
         if (! is_resource($rProcess)) {

//               stream_set_write_buffer($aPipes[0], 0);
//                fputs($aPipes[0],$sPath."\n",strlen($sPath)+1);
                fwrite($aPipes[0],$sPath."\n");                
//                fflush($aPipes[0]);
                
                sleep(1);                                           
                $sResponse = fread($aPipes[1],2);
                var_dump($sResponse);            
         }   

/*
   NOTE : Commented lines don't influence the result if they are not commented 
   The executable does work right, tested on the command line
   If you swap the executable with a php script that does the same thing (reads in file paths separated with \n and writes 2 character responses) everything functions as expected 
*/


Expected result:
----------------
var_dump  the 2 characters read from the output of the child

Actual result:
--------------
Script hangs , hang caused by the lien that reads: 

$sResponse = fread($aPipes[1],2);



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-27 08:56 UTC] TorokAlpar at Gmail dot com
I have tried with the latest snapshot, the result is the same
 [2008-12-18 22:49 UTC] scruoge at gmail dot com
PHP Version 5.2.6, Apache/2.0.63 Handler
Linux hostname 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686
I have exactly same bug. Script just silently dies.
here is the code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

function test1($line)
{
	$line = trim($line, "\r\n");
	$desc = array(
	   0 => array("pipe", "r"),
	   1 => array("pipe", "w"),
	   2 => array("file", "/home/user/error-output.txt", "a")
	);
	$process = proc_open('/usr/local/bin/client', $desc, $pipes);
	if (is_resource($process)) {
		fwrite($pipes[0], $line);
		fclose($pipes[0]);
		$line = '';
		while (($s = fgets($pipes[1], 1000)) !== false)
		{
			$s = trim($s, "\r\n");
			$line.= $s;
			if(strpos($s, '<end>') !== false) break;
		}
		fclose($pipes[1]);
		$return_value = proc_close($process);
	}
	$line = trim($line, "\r\n");
	return $line;
}

echo test1('asdfasdf<end>')."\n";

?>
 [2009-02-13 00:16 UTC] jani@php.net
Please try using this CVS snapshot:

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

  http://windows.php.net/snapshots/


 [2009-02-20 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".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC