
Solid, safe website tools.
Whatever your need, Will Bontrager builds powerful software solutions.
|
(Get Attention Ticker for your web site)
Debugging Code that Can Save Hours of FrustrationBy Will Bontrager Some servers just don't provide very good messages in error logs. This is especially true of shared servers, where configuring error logs to be verbose could degrade server performance for all accounts and quickly grow the error log to overwhelming size. And some hosting companies don't give their clients access to their error logs at all. It's hard to debug code when error messages are less than specific. "Premature end of script headers" is about as useless as "Your script has an error." What is needed is a clue to the type of error and the general location of the error. And, while we're making a list, let's also have an adequate description of the error and the exact location of any offending characters. This Perl CGI debugging code comes to the rescue: Put the code near the top of the script, immediately below the first line would work. It prints any error messages right in the current browser window. It doesn't work on all servers, and the script must have correct permissions. But if it does work on your server, you have a wonderful tool to help quickly debug scripts. If you prefer to have error messages recorded in a custom error log file on the server, try this:
Replace cgi-error-log with your preferred error log file name. If the script is run, yet the error log file isn't created, it may have been created in a different directory. To fix, include the complete server path as part of the error log file name in the above code. Sometimes the bug is of such a nature that the Perl compiler can't find the specific line or offending character. In those cases, the "Frequently Asked Questions" page might be able to help. Check the answers of questions relating to "Internal Server Error" and "Premature end of script headers." The former has a list of many common reasons for the Internal Server Error. September 24, 2006 Please note: Articles on this website are presented "as is". However - If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Rate this blog post.
No page reload! |
|
|
© 1998-2001 William and Mari Bontrager |
|