I'm trying to write to stdout (or stderr) using PHP with Apache (running in the foreground in Docker).
These works:
file_put_contents( "php://stderr","works" );
file_put_contents( "php://stdout","works" );
$fh = fopen('php://stdout','w'); fwrite($fh, "works");
But these do not:
$stdout = fopen ("/dev/stdout","w"); fwrite($stdout, "fails");
$stderr = fopen ("/dev/stderr","w"); fwrite($stderr, "fails");
echo "fd1 exists:" . (file_exists('/proc/self/fd/1') ? 'yes' : 'no');
echo "fd1 writable:" . (is_writable('/proc/self/fd/1') ? 'yes' : 'no');
echo "stdout exists:" . (file_exists('/dev/stdout') ? 'yes' : 'no');
echo "stdout writable:" . (is_writable('/dev/stdout') ? 'yes' : 'no');
file_put_contents( "/proc/self/fd/1", "fails" );
file_put_contents( "/proc/self/fd/2", "fails" );
file_put_contents( "/dev/stdout", "fails" );
fwrite(STDOUT, 'fails');
fwrite(STDERR, 'fails');
/dev/stdout do exist, but is not writable. also fopen('/dev/stdout')
returns FALSE.
fd1 exists:yes
fd1 writable:no
stdout exists:yes
stdout writable:no
More info:
- I tried setting
error_log = /dev/stdout
in php.ini, but it doesn't work - I tried Docker command
RUN ln -sf /dev/stdout stdout.log
and then writing tostdout.log
in PHP, but nope.
Again, what is php://stdout doing that I don't?