How to print a debug log?
I'd like to debug some PHP code, but I guess printing a log to screen or file is fine for me.
How should I print a log in PHP code?
printf seems to go to HTML output not the console.
I have Apache server executing the PHP code.
Verified Answer (183 Votes) ✓
A lesser known trick is that mod_php maps stderr to the Apache log. And, there is a stream for that, so
file_put_contents('php://stderr', print_r($foo, TRUE)) will nicely dump the value of
$foo into the Apache error log.
Answer #2 (138 Votes)
might be useful
Answer #3 (25 Votes)
You can use error_log to send to your servers error log file (or an optional other file if you'd like)