Archive

Posts Tagged ‘debugging’

PHP’s error_log function

December 5th, 2008

I don’t know why it took so long for me to discover error_log, considering how quickly it has become indispensable for debugging my Facebook application.

Since all my PHP output is filtered through Facebook’s servers, I can’t always easily see the errors that crop up. This is where error_log comes in: it allows me to write entries to my Apache log file by passing in ‘0′ (zero) as the second parameter:

error_log("There was an error executing functionName($param1, \"$param2\", $param3)", 0);

(Technically, the zero just means it logs to PHP’s logfile, but for most setups that will be Apache’s.)

Since I have tail -f /var/log/httpd/error_log running on my second screen, errors will show up alongside Apache and normal PHP errors:

[Fri Dec 05 09:24:32 2008] [error] [client xxx.xxx.xxx.xxx] There was an error executing functionName(123, "contents", 456)

It makes debugging my scripts so much easier.

Aidan Findlater Impersonal , ,