Facebook debugging in PHP

I’m using PHP to develop my facebook apps. I’ve never done server-side development before, and one of the more awkward aspects is debugging. Luckily, I have done plenty of other remote debugging before, and a lot of the general techniques cross over. Here’s what I use at the moment:

Error logging to a file

PHP writes out a message to /etc/httpd/logs/error_log whenever it hits a syntax error. I generally run this command line to see the latest errors:
tail -n 500 /etc/httpd/logs/error_log

You can also insert your own logging messages into the file using the error_log() function.

Error logging to the HTML output

Sometimes it’s quicker to see the errors right in the browser as you try to load the page. I don’t use this much for syntax errors, but I do often add print() statements to show debugging information. One of the most useful tools is the print_r() function, which displays all the internal elements of arrays and objects.

You can enable inline error reporting by changing the php_flag display_errors line in your php.ini file to ‘on’ if you want to see syntax errors too.

Ajax errors

Debugging Ajax-style server requests was very tricky. One way I found in Facebook was setting the response type to RAW, and then setting that response text directly into a div. Even better was using FireBug, a great extension for Firefox that gives you a lot of information about what the browser is up to.

Choose Tools->Firebug->Open Firebug from the main menu, and click the checkbox in the lower pane that appears to turn it on. Navigate to your ajax page, and click on the Console tab in the FireBug pane. You should now see a POST entry appear for every ajax call you make, with the time it took to get a response. Twirling that open shows a complete description of what you sent, and what the server returned, in Headers, Post and Response tabs.

Advanced debugging

My needs are simple enough that I haven’t moved beyond these basic logging techniques, but you can check out this page if you’re interested in stepping through code and inspecting variables using a traditional debugger with PHP.

Facebook App User Counts:
Funhouse Photo – 917 total, 57 active. Still very unimpressive growth.
Event Connector – 4 total. I’m giving Google adwords a try, to see if I can reach event organizers with he keywords ‘facebook event promotion’, and a very low budget.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: