PHP write to STDERR

I'm using PHP at the command line to write a bunch of SQL commands out. If an error arose I wanted it to go to STDERR instead of being printed out and messing up my SQL. PHP, being a web based language, doesn't make this real obvious. The solution ended up being error_log(), which if called from the CLI sends a message to STDERR.

error_log("This message will go to STDERR");

In web context error_log() logs to Apache's error_log, where ever that is mapped.

Leave A Reply - 1 Reply
Replies
Alex 2010-12-23 10:06pm - No Email - Logged IP: 174.1.235.8

Can you not fprintf to stderr by default? :P

All content licensed under the Creative Commons License