Page 1 of 1

[urgent] proc_open, buffers, blocking help? thankyou please

Posted: Thu Dec 06, 2007 3:51 pm
by nathanr
Hoping somebody out there may have come across this one..

Code: Select all

$descriptor = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"), 
   2 => array("pipe", "w") 
);
$process = proc_open('mysql', $descriptor, $pipes);

fwrite($pipes[0], 'show databases;');
echo stream_get_contents($pipes[1]); //won't work, crash, time out.. nothing returns
//........
doesn't work as we need to..

Code: Select all

$descriptor = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"), 
   2 => array("pipe", "w") 
);
$process = proc_open('mysql', $descriptor, $pipes);

fwrite($pipes[0], 'show databases;');
fclose($pipes[0]); // note the fclose
echo stream_get_contents($pipes[1]); // works
// .................
I don't want to fclose pipes[0] though, as i want to keep it open and keep writing to it, alternating with reading from pipes[1] and [2]..
so a replacement for fclose.. here's what I've tried with no success

Code: Select all

fwrite($pipes[0], 'show databases;'."\n");
##################

fflush($pipes[0]);
##################

stream_set_write_buffer($pipes[0], 0);
##################

stream_set_blocking($pipes[0], false);
##################
none of the above in any order work for me.. php 5.1.6/5.2.4/ linux boxes

trying to:
spawn process, keep open for the duration of script execution, read and write multiple times to same process, then close - how?

the problem with the aforementioned method.
nothing returns to stdout until an fclose happens on stdin, so need a method of forcing this to happen without closing stdin

notes: i'm aware stream_get_contents looks for an eof, however I've tried all fget methods etc and there is 0 data in std out until stdin has been closed.

thanks in advance

Posted: Fri Dec 07, 2007 4:35 pm
by volka
I don't think you can use the mysql client this way.
Why can't you use php's mysql/mysqli/pdo extension?

Posted: Mon Dec 10, 2007 12:03 pm
by nathanr
well because I want to use mysql clients command line --xml option to retireve xml instead of mimicking it through php classes..