|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 21:00:01 2025 UTC |
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"; ?>