I have two scripts :
The first one contains the folowing code:
<?php
// ...
echo date('H:i:s'), PHP_EOL;
$stream = ssh2_exec($session, 'php my-second-script.php');
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream, 4096)) {
$data .= $buf;
}
fclose($stream);
echo date('H:i:s'), PHP_EOL;
// ...
The second one just contains the following code:
<?php
sleep(15);
echo 'OK', PHP_EOL;
I don't understand why sometimes when I run my first script, it waits for the second script to run but sometimes no.
For example, when it works I have the following output :
14:16:10
14:16:25
And sometimes I have this:
14:17:13
14:17:14
I also read the post ssh2_exec: wait end of a process to run next and the guy who answered said that "the command may not finish properly if the stream is not read to end". Someone can explain to me this?