Write to php: // stderr

I am trying to use php: // stderr to write logs to work. I am using Slim framework which uses @fopen('php://stderr', 'w') for logging and really wants this to work.

The following test cases should work, but only the first:

 // 1. error_log - works fine error_log("Written through the error_log function", 0); // 2. PHP wrapper, ie php://stderr - does not work $stderr = fopen( 'php://stderr', 'w' ); fwrite($stderr, "Written through the PHP error stream" ); fclose($stderr); // 3. PHP wrapper also, different syntax, just to be safe - no effect either file_put_contents( "php://stderr","Hello World" ); // 4. PHP wrapper, this time using this elusive constant referred to in the manual - result: "Notice: Use of undefined constant STDERR - assumed 'STDERR' ", ie: failed also! file_put_contents( STDERR, "Hello World" ); 

I looked at the PHP and Googling tutorial a lot, but without much help.

In particular, the following quote from the PHP manual on wrappers is confusing:

It is recommended that you simply use the constants STDIN, STDOUT, and STDERR instead of manually opening the streams using these [php: // stdin, php: // stdout and php: // stderr] wrappers links. "

... given the above notice is undefined. (I suspect that these constants can be used with the PHP CLI - only?), But the page I'm quoting is not listed.)

I was wondering if this could be Windows, since I am running XAMPP with PHP 5.3.8 for development, but given the lack of themes on Google and the comments on PHP.net, I'm not sure anymore. I do not have access to the logs of my production server right now to check.

+4
source share
2 answers

Nothing, get it. I did not quite understand the difference between php://stderr and error_log :

error_log writes to the PHP error log (for example: D: \ xampp \ php \ logs \ php_error_log)

php://stderr writes to the server / Apache error log (for example: D: \ xampp \ apache \ logs \ error.log)

Hope this helps someone else.

+7
source

If you just use the built-in PHP web server (starting with PHP 5.4.0), then php://stderr will be displayed on the console screen on which the built-in PHP web server is running.

+1
source

All Articles