PHP obtiene flujo de salida o simplemente eco
Frecuentes
Visto 12,551 veces
4 Respuestas
9
The first thing that comes to mind for me is output buffering. echo
y print
interface with the output buffering mechanism, but directly writing to stdout bypasses it.
Considere este guión:
<?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;
que salidas:
FWRITTEN
echo output
Also echo
which demonstrates that echo
is buffered, and fwrite is not.
Respondido 25 ago 12, 20:08
Aquí php://stdout
is not buffered stream, fwrite can buffer the output using php://output
- Papana Venkat
nice answer. it helps me a lot. - konohanaruto
2
La diferencia es que echo
escribe a 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
Respondido 25 ago 12, 20:08
0
In addition to the already noted technical difference, there's also the obvious difference in style and convention. echo
/print
is the normal way of producing output in PHP; writing to output as if to a file would be abnormal and potentially confusing. For the sake of the clarity of your intent, I wouldn't advise doing this unless you have a good reason to do so.
Respondido 25 ago 12, 20:08
0
Aquí php://stdout
is not buffered stream, fwrite can buffer the output using php://output
respondido 18 nov., 13:10
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php or haz tu propia pregunta.
stdout being the IO stream of functions like echo and printr I would say there is not real difference other than accessing it directly. - Sammaye