Page 1 of 1
PHP output streams
Posted: Tue Feb 07, 2006 7:42 pm
by quocbao
Hi , i have some small questions
What different between using echo and php output stream ?
What different between php://stdout and php://output
Why use php stream and which method will be better for output ?
Code: Select all
<?
$f = fopen("php://output" , "w");
fwrite($f,"Hello world");
fclose($f);
?>
Posted: Tue Feb 07, 2006 7:55 pm
by AKA Panama Jack
Let's see using fopen adds alot of extra unneeded overhead, slower and just the worst way ever to send output to a browser.
It's like driving 5 miles out of your way to get from point A to point B when you could have diven 100 feet in a straight line to get from point A to point B.
Re: PHP output streams
Posted: Tue Feb 07, 2006 8:30 pm
by Christopher
quocbao wrote:What different between using echo and php output stream ?
Nothing as they have the same result.
quocbao wrote:What different between php://stdout and php://output
See
http://us3.php.net/manual/en/wrappers.php.php or more general
http://us3.php.net/manual/en/wrappers.php
quocbao wrote:Why use php stream and which method will be better for output ?
If you are outputting to the HTTP Response (or stdout in command line) then echo() is the simplest way to output text. Read/writing to files, sockets, etc. is when you need to use other functions.
There also is a standard Streams library
http://www.php.net/manual/en/ref.stream.php
Posted: Tue Feb 07, 2006 8:42 pm
by quocbao
php://stdin, php://stdout and php://stderr allow access to the corresponding input or output stream of the PHP process.
php://output allows you to write to the output buffer mechanism in the same way as print() and echo().
That's clear
Thanks

!