[ale] simple PHP question on proc_open

Jay Loden jloden at toughguy.net
Mon Feb 12 18:52:09 EST 2007


On PHP 5.1.2 which is what I'm running, I think the problem is you need to specify a type of "pipe" and not file for the php://stderr like so: 

<?php

$cmd = 'date';

 $descriptors = array(
         0 => array("pipe", "r"),
         1 => array("pipe", "w"),
         2 => array("pipe", "php://stderr", "w")
   );
 $process = proc_open('/bin/date', $descriptors, $fd_set);
 if (is_resource($process)) {
        print "got it: " . stream_get_contents($fd_set[1]);
}  else { print "NO NO"; }
        proc_close ($process);
?>

The above executed fine on my system, running it from the command line. I believe if you run this from a webserver you'll need to specify the full path of /bin/date since the PATH env variable won't be passed the same if it's running as the apache user. 

-Jay

Jerry Yu wrote:
> Thanks, Jay. I tried with 'cwd' passed in. same error, still. 
> Here is the exact error I am getting:
> $ php j.php
> PHP Warning:  proc_open(): cannot seek on a pipe in /tmp/j.php on line 11
> sh: /date: No such file or directory
> got it
> 
> Same script, j.php runs w/o problem with PHP/4.3 on CentOS 4.
> 



More information about the Ale mailing list