rexkogitans rexkogitans - 1 year ago 141
Apache Configuration Question

PHP stdout not written

I am writing a PHP script running on an Apache httpd web server (not administrated by me). In a function, the variable

is given as function parameter, and the very beginning of the function is this:

if (isset($outfile))
$fh = fopen($outfile, 'wb');
$fh = fopen('php://stdout', 'w');
echo 'Hello, ';
fwrite($fh, 'World');

I call this function with
$outfile = NULL
, so
should point to stdout. I can strip down this even more by dropping the condition:

$fh = fopen('php://stdout', 'w');
echo 'Hello, ';
fwrite($fh, 'world');

The point is, it only outputs


instead of what I am expecting:

Hello, world!

How come and how can I circumvent this problem?

Answer Source

Use php://output instead of php://stdout. As the documentation says

php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print and echo.

php://stdout writes directly to the stdout file descriptor, so it won't be properly synchronized with the buffered output of echo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download