Debugging ‘Responseless’ HTTP Requests
When developing AJAX or Facebook web apps a lot of the time requests are fire and forget i.e. they are awaiting no specific response information from the application. Therefore we have no simple dump to screen solution for debugging our apps.
One workaround would be to save details to a db where they could be retrieved for analysis at a later time. This makes the data persistent but normally for debugging this is overkill. Log frameworks exist but sometimes incorporating third party software in is just bloat, especially in single developer projects.
The simplest alternative solution I can think of is to grab the request info needed and send it out to a mail address using PHP’s built in mail object:
$to = 'email@example.com'; $subj = 'Request variables'; $msg = 'Requested:\n'; foreach ( $_REQUEST as $k => $v ) $msg .= "\t$k = $v\n"; mail( $to, $subj, $msg );
Mailing debug output to a free mail provider such as gmail means you have a persistent copy of the data (in chronological order) in a few lines of code without needing to start building up sql or think about clogging up your host with yet more logs. Is there a better way?