473,416 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

proc_open and blocking fread / tri-directional pipes

Hello

I would like to call a unix shellscript from within a PHP script and
- write data to its STDIN
- read data from its STDOUT *and* STDERR
- get its exit code afterwards

proc_open seems to be the right thing to use but I have the problem that the called program gives >8kb data on both stdout/stderr back which causes my PHP script to simply hang in the fread call. To be precise the first 4096 "O" characters are read and displayed.

The problem is described in the first user comment to proc_open at www.php.net but the solution there writes stderr to a file (which never blocks) and therefore does not work for me.

Does anybody know a solution? stream_set_blocking sounds good but
simply calling it with $pipes[1] and $pipes[2] as "stream" argument does not have the wished effect.

bye & TIA,

-christian-

My test program:

$pipe_spec = array(
0 => array("pipe", "r"), # stdin
1 => array("pipe", "w"), # stdout
2 => array("pipe", "w") # stderr
);
$process = proc_open("/tmp/testshellskript", $pipe_spec, $pipes);

# stdin
if (fclose($pipes[0]) == 0) trigger_error("fclose0", E_USER_ERROR);

# stdout
while ( ! feof($pipes[1])) print fread($pipes[1], 8192);
if (fclose($pipes[1]) == 0) trigger_error("fclose1", E_USER_ERROR);

# stderr
if (fclose($pipes[2]) == 0) trigger_error("fclose2", E_USER_ERROR);

And the called shell script (writes the chars each 7000 times):

#!/usr/bin/perl
print(STDOUT ("O"x7000)."\n");
print(STDERR ("E"x7000)."\n");
Jul 17 '05 #1
0 2251

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan Little | last post by:
I'm struggling with proc_open(). What I'm trying to do is conduct an sftp session. The process appears to open fine, but anything I send to it with fwrite() is ignored, and any output from sftp is...
4
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the...
0
by: FrenKy | last post by:
Hi *. I get this error when trying to run proc_open() function: "Fatal error: Call to undefined function: proc_open() in /home/frantic/public_html/a/phpshell.pup on line 140" Does anybody...
0
by: yawnmoth | last post by:
popen / proc_open seem to be broken (as per PHP Bug #30463). As such, does anyone know if there are any alternatives to them? I tried to use fsockopen to load a bunch of instances of a script to...
2
by: razorfold | last post by:
Hi, I've been trying to run gpg through proc_open() and have failed all weekend. I keep getting this error from stderr: "/usr/bin/gpg: error while loading shared libraries: cannot restore...
0
by: yaront | last post by:
Hi, I'm using proc_open to start a process on a WindowsXP server. If the process that I start crashes for some reason, the whole PHP parsing hangs. When opening the TaskManager I can see my...
0
by: Mitch Amiano | last post by:
Tri-XML 2005 is on for July 28-30th, in Raleigh, NC. The conference index is at <http://www.trixml.org/confindex.shtml>. Curious readers can get an idea of the conference from a review of...
0
by: Scott Abel | last post by:
Tri-XML 2005 -- Annual Conference, July 28-29, 2005 -- McKimmon Center (NC State University) Info: http://www.trixml.org/confindex.shtml Three days -- only $199 Come to Tri-XML 2005 and learn...
1
by: Aaron Queenan | last post by:
Is there any way to have tri-state checkboxes in the TreeView, preferably without having to use the state icons for that purpose. Does anyone have or know of an implementation of tri-state...
0
by: Mitch Amiano | last post by:
I thought some of the list members might be interested (whether active or lurkers)... For the past few years, we've held the Tri-XML conference here in the Research Triangle Park area. This...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.