Skip to content

Instantly share code, notes, and snippets.

/Mac output Secret

Created May 29, 2015 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/c812e21d1244a8c137a8 to your computer and use it in GitHub Desktop.
Save anonymous/c812e21d1244a8c137a8 to your computer and use it in GitHub Desktop.
PHP 5.6.9 stream_get_contents usage
20:49 starting
20:49 proc_open finished
22:19 stream_get_contents 1 finished
22:19 fclose 1 finished
22:19 stream_get_contents 2 finished
22:19 fclose 2 finished
22:19 proc_close finished
array(3) {
["stdout"]=>
string(3) "bla"
["stderr"]=>
string(0) ""
["exitCode"]=>
int(0)
}
<?php
printTimeStatus("starting");
$command = '"'.PHP_BINARY.'" slowscript.php';
$pipes = [];
$resource = proc_open($command, [1 => ["pipe", "w"], 2 => ["pipe", "w"]], $pipes);
printTimeStatus("proc_open finished");
$stdout = stream_get_contents($pipes[1]);
printTimeStatus("stream_get_contents 1 finished");
fclose($pipes[1]);
printTimeStatus("fclose 1 finished");
$stderr = stream_get_contents($pipes[2]);
printTimeStatus("stream_get_contents 2 finished");
fclose($pipes[2]);
printTimeStatus("fclose 2 finished");
$exitCode = proc_close($resource);
printTimeStatus("proc_close finished");
var_dump( ["stdout"=>$stdout, "stderr"=>$stderr, "exitCode"=>$exitCode] );
function printTimeStatus($msg)
{
print date("i:s") . " $msg\n";
}
<?php
sleep(90);
print "bla";
20:52 starting
20:52 proc_open finished
21:27 stream_get_contents 1 finished
21:27 fclose 1 finished
22:03 stream_get_contents 2 finished
22:03 fclose 2 finished
22:22 proc_close finished
array(3) {
["stdout"]=>
string(0) ""
["stderr"]=>
string(0) ""
["exitCode"]=>
int(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment