PHP Debugging with Class
By Phil Glatz
It's hard to debug a CGI program. After all, you're not actually running it (unless your name is httpd). But when those bugs show up, a little creative thinking will help you overcome that limitation. Let's talk about a technique I've found to be very useful for debugging CGI programs written with the PHP scripting language. While the same basic idea could be applied to CGI programs written in other languages, the class extensions to PHP make the process a little more elegant, as well as easy to apply to many CGI scripts without a lot of extra work. (If you're not familiar with PHP, see the box titled "
What Is PHP?")
Debugging a CGI Script
When it comes to getting inside a CGI script, you can't use traditional techniques like PRINT statements or tracing program execution or failure. However, a CGI program does run linearly, as does any other structured program, so simple debugging statements can be directed to other output devices, such as a spool file. So, yes, you can insert PRINT statements within CGI to report the state of program variables or to display text strings to alert the developer of the progress through a program. But this sort of brute-force technique will interfere with the contents of the browser window, often causing more problems than it solves. Also, debugging information can be quite bewildering to the user when it appears on a production site, and there will be times when you still need to continue debugging even after a script goes live.<>