PHP STDERR FAQ - How do I write to STDERR in a PHP script, specifically a PHP command line script?
I've written a lot of my command line scripts in PHP lately, and I just ran across this problem in my own script, how to write to STDERR in PHP. Fortunately the solution is easy, just use the PHP fwrite function like this:
fwrite(STDERR, “hello, world\n”);
Or, in a more real-world example, here's how I'm writing MySQL error messages to STDERR in PHP: