Odd Reload Behavior
I've recently written some code that behaves in a way I don't understand. It's basically a Handler that works for more than one VirtualHost. For each VirtualHost that uses the Handler, a call is made to App-loadPages(). It crawls an accompanying lib directory and loads the pages into a hashref, which is then stored in a global hash inside App. Later, during requests, the Handler calls App-getPages(key), where key is a unique name for each virtual host. This _should_ return a hashref full of page objects, but it returns undef. Since the App module is pre-loaded (in startup.pl), and loadPages() fills the hash, shouldn't the Handler's calls to getPages(key) work? I know it can, because I had it working a couple weeks ago, but something has broken it. It looks as though this works during the first 'load' that Apache does, which I'm assuming is the phase that checks for errors. The second phase seems to cause my global hash to get undef'ed, even though the loadPages() method works properly. I can divulge more code if necessary, but perhaps someone can clue me into why this happens. Cory 'G' Watson http://www.loggerithim.org -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Trouble getting mod_perl and apache running with Apache::DBI
Hello everyone, I've set mod_perl up with Apache::DBI on several servers, both with mod_perl from RPM's and building it myself, but I am having a horrible time with a new server I've just built. Go easy, I'm still new at it, though. And I welcome any and all constructive criticism for my config files, etc. Here are the specs: RH 7.3, mod_perl 1.2.6 from RPM, Apache::DBI 0.92, DBI 1.37. Now, here's what I'm defining in httpd.conf: snip httpd.conf IfModule mod_perl.c Alias /perl /var/www/perl Directory /var/www/perl SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI /Directory #PerlHandler HTML::Mason::ApacheHandler PerlSetVar MasonCompRoot /var/www/html/mason PerlSetVar MasonDataDir /var/mason PerlSetVar MasonAllowGlobals $dbh #PerlAddVar MasonAllowGlobals $session #PerlAddVar MasonAllowGlobals %session #PerlAddVar MasonAllowGlobals $sys #PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession #PerlSetVar MasonSessionClass Apache::Session::File #PerlSetVar MasonSessionDirectory /tmp/sessions #PerlSetVar MasonSessionLockDirectory /tmp/sessions PerlSetEnv DBI_TRACE 3=/tmp/dbitrace.log PerlRequire /etc/httpd/conf/startup.pl #PerlModule Apache::DBI AddType text/html .mhtml AddType text/html .mason Location /mason SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler Options +ExecCGI /Location /IfModule /snip httpd.conf Here's my startup.pl: snip startup.pl #!/usr/bin/perl use warnings; use strict; # Extend @INC if needed #use lib qw(/dir/foo /dir/bar); use lib qw(/var/www/html/mason/lib); use lib qw(/var/www/html/mason/hrtime/lib); use vars qw($dbh %session); # Make sure we are in a sane environment. $ENV{MOD_PERL} or die not running under mod_perl!; # For things in the /perl URL use Apache::Registry; #$KO::server_root = /var/www/html/mason/db; #use KO::DBI::Connect qw(:all); # Load Perl modules of your choice here # This code is interpreted *once* when the server starts use LWP::UserAgent (); #use Apache::DBI (); use DBI(); # Tell me more about warnings use Carp(); $SIG{__WARN__} = \Carp::cluck; # Load CGI.pm and call its compile() method to precompile # (but not to import) its autoloaded methods. use CGI (); CGI-compile(':all'); # Initialize the database connections for each child =pod Apache::DBI-connect_on_init (DBI:Pg:dbname=auth;host=localhost;port=5432, root,, { PrintError = 1, # warn() on errors RaiseError = 0, # don't die on error AutoCommit = 1, # commit executes immediately } ); =cut 1; /snip startup.pl What's happening is that with use Apache::DBI uncommented in either the httpd.conf or startup.pl Apache does not start. This is what error_log reports: [Thu Aug 14 14:59:49 2003] [notice] Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.7 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.1.2 mod_perl/1.26 mod_throttle/3.1.2 configured -- resuming normal operations [Thu Aug 14 14:59:49 2003] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 14 14:59:49 2003] [notice] Accept mutex: sysvsem (Default: sysvsem) [Fri Aug 15 10:08:43 2003] [notice] caught SIGTERM, shutting down When I try to pull up anything the connection is refused (because the server is down). I've just been commenting and uncommenting stuff until it worked. The weird thing is that there are no real error messages from mod_perl in the apache logs. Can anyone help? Thanks, Kevin -- K Old [EMAIL PROTECTED] -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Trouble getting mod_perl and apache running with Apache::DBI
I left out my version of Perl. I'm using 5.6.1 from RPM. Kevin On Fri, 2003-08-15 at 10:34, K Old wrote: Hello everyone, I've set mod_perl up with Apache::DBI on several servers, both with mod_perl from RPM's and building it myself, but I am having a horrible time with a new server I've just built. Go easy, I'm still new at it, though. And I welcome any and all constructive criticism for my config files, etc. Here are the specs: RH 7.3, mod_perl 1.2.6 from RPM, Apache::DBI 0.92, DBI 1.37. Now, here's what I'm defining in httpd.conf: snip httpd.conf IfModule mod_perl.c Alias /perl /var/www/perl Directory /var/www/perl SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI /Directory #PerlHandler HTML::Mason::ApacheHandler PerlSetVar MasonCompRoot /var/www/html/mason PerlSetVar MasonDataDir /var/mason PerlSetVar MasonAllowGlobals $dbh #PerlAddVar MasonAllowGlobals $session #PerlAddVar MasonAllowGlobals %session #PerlAddVar MasonAllowGlobals $sys #PerlSetVar MasonRequestClass MasonX::Request::WithApacheSession #PerlSetVar MasonSessionClass Apache::Session::File #PerlSetVar MasonSessionDirectory /tmp/sessions #PerlSetVar MasonSessionLockDirectory /tmp/sessions PerlSetEnv DBI_TRACE 3=/tmp/dbitrace.log PerlRequire /etc/httpd/conf/startup.pl #PerlModule Apache::DBI AddType text/html .mhtml AddType text/html .mason Location /mason SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler Options +ExecCGI /Location /IfModule /snip httpd.conf Here's my startup.pl: snip startup.pl #!/usr/bin/perl use warnings; use strict; # Extend @INC if needed #use lib qw(/dir/foo /dir/bar); use lib qw(/var/www/html/mason/lib); use lib qw(/var/www/html/mason/hrtime/lib); use vars qw($dbh %session); # Make sure we are in a sane environment. $ENV{MOD_PERL} or die not running under mod_perl!; # For things in the /perl URL use Apache::Registry; #$KO::server_root = /var/www/html/mason/db; #use KO::DBI::Connect qw(:all); # Load Perl modules of your choice here # This code is interpreted *once* when the server starts use LWP::UserAgent (); #use Apache::DBI (); use DBI(); # Tell me more about warnings use Carp(); $SIG{__WARN__} = \Carp::cluck; # Load CGI.pm and call its compile() method to precompile # (but not to import) its autoloaded methods. use CGI (); CGI-compile(':all'); # Initialize the database connections for each child =pod Apache::DBI-connect_on_init (DBI:Pg:dbname=auth;host=localhost;port=5432, root,, { PrintError = 1, # warn() on errors RaiseError = 0, # don't die on error AutoCommit = 1, # commit executes immediately } ); =cut 1; /snip startup.pl What's happening is that with use Apache::DBI uncommented in either the httpd.conf or startup.pl Apache does not start. This is what error_log reports: [Thu Aug 14 14:59:49 2003] [notice] Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.7 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.1.2 mod_perl/1.26 mod_throttle/3.1.2 configured -- resuming normal operations [Thu Aug 14 14:59:49 2003] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Thu Aug 14 14:59:49 2003] [notice] Accept mutex: sysvsem (Default: sysvsem) [Fri Aug 15 10:08:43 2003] [notice] caught SIGTERM, shutting down When I try to pull up anything the connection is refused (because the server is down). I've just been commenting and uncommenting stuff until it worked. The weird thing is that there are no real error messages from mod_perl in the apache logs. Can anyone help? Thanks, Kevin -- K Old [EMAIL PROTECTED] -- K Old [EMAIL PROTECTED] -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Hi there, On Fri, 15 Aug 2003, Cory 'G' Watson wrote: It looks as though this works during the first 'load' that Apache does, which I'm assuming is the phase that checks for errors. The second phase seems to cause my global hash to get undef'ed, even though the loadPages() method works properly. I'm not entirely convinced of the explanation, but have you tried testing the value of $Apache::Server::ReStarting in the code that fills the hash? It's in the Guide. Your message was a bit cavalier about what's a hash and what's a hashref, are you sure you aren't just missing a dereference somewhere? Have you got 'use strict' and warnings on? 73, Ged. -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
On Friday, August 15, 2003, at 12:43 PM, Ged Haywood wrote: I'm not entirely convinced of the explanation, but have you tried testing the value of $Apache::Server::ReStarting in the code that fills the hash? It's in the Guide. I'm not convinced of it either. :) This code _would_ run twice, so I can protect it using the variable you specified. I didn't know it existed. List messages seem to say that this shouldn't be used? Your message was a bit cavalier about what's a hash and what's a hashref, are you sure you aren't just missing a dereference somewhere? Have you got 'use strict' and warnings on. It's a difficult concept to relay without pasting a bunch of code. -- App.pm: package App; my %pageobjs; sub loadApp { my $self = shift(); my $name = shift(); my $libdir = shift(); my %pages; opendir(LIBDIR, $libdir); while(there are files to check) { # blah, if the file is a .pm, require and instantiate it into $page $pages{$pageObjectName} = $page; closedir(LOBDIR); $pageobjs{$name} = \%pages; } sub getPages { my $self = shift(); my $name = shift(); return $pageobjs{$name}; } -- startup.pl: use App; Sooo, using the above code, the VHost uses: PerlVar app blah Perl App-loadApp(blah, /usr/local/blah/lib); /Perl And, inside the Handler: my $app = $r-dir_config(app); my $hashRefOfPageObjs = App-getPages($app); And $hashRefOfPageObjs is always undef; Ignore syntax errors and lack of declarations, as I just threw that together from memory into the ol' MUA here. Does that make more sense? I believe I had this working at one point, but something has caused it go south. The double load I see (which you explained with your Restarting tip) was suspect only because if I put code into App which Data::Dumper's the hash, there is something in it, but it disappears between the first load and the first request. It looks like Perl sections are executed twice, but this shouldn't cause the variable to go undefined. Cory 'G' Watson http://www.loggerithim.org -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Hello again, On Fri, 15 Aug 2003, Cory 'G' Watson wrote: PerlVar app blah Perl App-loadApp(blah, /usr/local/blah/lib); /Perl [snip] Ignore syntax errors and lack of declarations, as I just threw that together from memory The guesswork would be a lot easier if it didn't involve so much guesswork. :) Have you read http://perl.apache.org/docs/1.0/guide/config.html#PerlSetVar_and_PerlAddVar and http://perl.apache.org/docs/1.0/guide/config.html#Apache_Configuration_in_Perl ? 73, Ged. -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html