What would be the differnce in php command line app of just echoing or printf etc some string as opposed to getting sdtout stream and writing to it i.e.
$stdout = fopen('php://stdout', 'w');
The first thing that comes to mind for me is output buffering. echo
and print
interface with the output buffering mechanism, but directly writing to stdout bypasses it.
Consider this script:
<?php
$stdout = fopen('php://stdout', 'w');
ob_start();
echo "echo output\n";
fwrite($stdout, "FWRITTEN\n");
echo "Also echo\n";
$out = ob_get_clean();
echo $out;
which outputs:
FWRITTEN
echo output
Also echo
which demonstrates that echo
is buffered, and fwrite is not.
The difference is that echo
writes to php://output
which is the output buffer stream.
However, php://stdout
gives you direct access to the processes' output stream which is unbuffered.
Further information regarding streams can be found in the manual: http://www.php.net/manual/en/wrappers.php.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With