Show Contents Previous Page Next Page Chapter 2 - A First Module / Troubleshooting Modules In this section...
Ironically, debugging misbehaving Apache Perl modules is not as straightforward
as debugging C modules. This is because the current version of the Perl source-level
debugger can't work when the Perl interpreter is embedded in another program.
As of this writing, there is a pre-alpha version of a If you are using the Using Apache::FakeRequest for debugging Show Contents Go to Top Previous Page Next Page If you are using the full Example 2-5 shows how Next, we create a new fake request object. Apache::FakeRequest::new()
can be called with a series of name=value pairs. Each name corresponds to a
method that a real Apache request object would respond to. When your module
calls the method without any arguments, Now it's simply a matter of calling our module's handler with the fake request object. If you're using the Perl debugger, you can step into the module's code and watch what it does. Should you want to customize Example 2-5. This Apache::FakeRequest Wrapper Can Be Used to Debug Apache::Hello #!/usr/local/bin/perl use lib '/usr/local/apache/lib/perl'; use Apache::FakeRequest (); use Apache::Hello (); my $request = Apache::FakeRequest->new('get_remote_host'=>'foobar.com');Show Contents Go to Top Previous Page Next Page Another useful debugging tool for Apache Perl modules is Apache::Debug defines a single subroutine named dump(). When dump() is called it sends copious debugging information to the remote browser. Hopefully some of the information will help you figure out what's going on. It's very simple to use Apache::Debug::dump($r, SERVER_ERROR, "Can't find configuration file!"); The three arguments to dump() are the request object, an error code to return to Apache (usually SERVER_ERROR), and an error message to print at the top of the debugging output.
Environment variables for debugging Show Contents Go to Top Previous Page Next PageA pair of environment variables control various aspects of the embedded Perl interpreter's execution and can be used to help debug particularly obstinate problems.
When % setenv MOD_PERL_TRACE dh % ~www/bin/httpd -X The first line sets Here's the complete list of trace options:
With Apache Versions 1.3 and higher, If you are experiencing this problem and your code does not contain any END
blocks or DESTROY methods that need to be run during child server shutdown,
you can avoid this problem by setting the PerlSetEnv PERL_DESTRUCT_LEVEL -1 Common Apache Perl module problems Show Contents Go to Top Previous Page Next PageCertain types of problems are common in Apache Perl modules. One common pattern is that the code will seem to fail at random. The first time you fetch a page generated by an Apache Perl module, it will work fine. The second time you fetch it, it won't. If you reload repeatedly, it will sometimes work and sometimes fail, seemingly haphazardly. This pattern is usually due to Apache's preforking behavior. Multiple instances of your module are running, each one in a separate process. In one or more of the processes, the module has crashed because some unexpected sequence of inputs has led it to corrupt a data structure (or something similar). In other processes, the module is still functioning (so far). You'll never be able to figure out what's going on under these circumstances. Kill httpd and relaunch it with the -X flag. With only one process running, you can more easily figure out what inputs cause the module to misbehave. Many Apache Perl module bugs are due to a wanton use of global variables. The very first time the module is called, globals are initialized to their undefined states in the way that conventional Perl scripts expect. However, in subsequent calls the globals will contain information left over from previous invocations of the script. This will cause scripts that depend on globals being initially undefined to fail. Suspect this problem if your pages exhibit a pattern of progressive decay in which they seem to work at first and then fail with increasing frequency. Also be aware that certain actions that are second nature to Perl programmers, such as calling die() or exit() to abort a script prematurely, may not have quite the result you expect in the context of an Apache Perl module. Under some circumstances a call to exit() within a module has been known to make the server misbehave in strange ways. Use Apache::exit() instead. die() should be reserved for truly unrecoverable errors. die() generally causes the browser to display an "Internal Error" message. It's better to replace die() with a procedure that displays a helpful error message in the browser window and returns control to Apache. Several techniques for doing this appear in the examples in subsequent chapters. The next chapter takes you on a tour through the innards of the Apache module API. You'll learn everything you ever wanted to know about request records, connection records, and transaction handlers. Footnotes 9 There are several directives related to managing the number of servers on the farm; these include StartServers, MaxSpareServers, MinSpareServers, and MaxClients. Show Contents Go to Top Previous Page Next PageCopyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |