PHP obtiene flujo de salida o simplemente eco

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');

preguntado el 25 de agosto de 12 a las 20:08

stdout being the IO stream of functions like echo and printr I would say there is not real difference other than accessing it directly. -

4 Respuestas

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

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

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

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 or haz tu propia pregunta.