Shortly after finishing the PHP AP5L_Debug class, I encountered a nasty problem with an AJAX enabled page. Although it’s possible to include diagnostic information in an AJAX response, the client side JavaScript has to figure out it’s there and then figure out how to display it in a sensible way, which also means putting it on the page in some dynamic HTML, or extracting it in a debugger. That’s just not fun.

Or you can try setting up an XDEBUG connection, which seems like a lot of work for a couple of diagnostic messages, and if you’re running on some shared hosting plan, you can probably forget about that anyhow.

So I figured why not just route the diagnostics out through a socket and write the output on a console somewhere?

So after a little work, AP5L_Debug now offers two variations.

  • AP5L_Debug_Stdout just echoes the data to the output stream (well not quite: if no headers have been sent, it buffers the data and then writes everything on the first post-header output, or on an explicit flush).
  • AP5L_Debug_Udp sends the data to the address and port of your choice. There’s also AP5L_Debug_Listener, which is a crude command line tool that reads data from the port and dumps the information to the console.

It worked like a charm. The diagnostics identified what was a pretty simple mistake, I fixed the code, and the problem was solved in no time.

Also, since the diagnostics don’t mess up the generated page, I can see using this technique even when there’s no AJAX involved. That’s more than welcome.

Mastodon