Ben PHP TCL komut arıyorum. Ben emin komut sona erdi yapmak için PHP TCL sürecin benzersiz bir dize gönderiyorum.
Ben bu dizeyi göndermek yoksa o PHP benim fread sonsuza kadar bloke edilir.
/ / PHP kodu
<?php
$id = 'done'; //Unique string
$app = 'c:/wamp/www/tcl/bin/tclsh84.exe';
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("pipe","w")
) ;
$process = proc_open($app, $descriptorspec, $pipes);
if (is_resource($process))
{
for($i=0;$i<2;$i++)
{
$output = '';
$continue = true;
$cTimeout = 0;
echo 'loop ', $i, "\n";
fwrite($pipes[0], "source c:/wamp/www/tcl/bin/helloworld.tcl\n");
echo "waiting for idle\n";
$timeout = time();
do {
$read=array($pipes[1]);
$write=array();
$except=array($pipes[1]);
$ready = stream_select($read, $write, $except, 1, 0);
$dif = time()- $timeout;
if ( $ready && $read )
{
$output .= fread($pipes[1], 2048); // is blocked indefinitely
// if the delimiter id shows up in $output
if ( false!==strpos($output, $id) ) {
// the script is done
$continue = false;
}
}
if($dif > 5) //timeout value not working
{
$continue = false;
}
} while($continue);
echo 'loop ', $i, "$output finished\n";
}
proc_close($process);
}
?>
/ / TCL code
"merhaba" koyar
If i sends "done" from TCL, then my PHP script ends . But I don't want to send just done, instead I need to do with the help of a timeout . i.e I want to wait for a certain period of time for the unique string , else I should exit . But I can't seem to implement the timeout in this case.
Kimse bana rehberlik edin.