Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have recently installed mod_perl on my development server to assess the performance benefits often claimed of it. For the most part I have been absolutely stunned by the massive speed increases I have witnessed through its usage. However, I have come up against a major barrier: I can't connect to any MySQL DB server(s) from scripts running under mod_perl. If I disable mod_perl, then these same scripts work fine. I am at a loss as to what's going wrong. I have discussed this on various mailing lists without resolving the problem. Now, I throw myself on the mercy of our esteemed monks - in the hope that I can get these scripts working.
Server Configuration:
The DB works fine: I can connect via MySQLAdmin; I can connect via PHP4; I can connect via CGI; I cannot connect via mod_perl.
The relevant section of "httpd.config" is as follows:
LoadModule perl_module modules/ApacheModulePerl <Files *.pl> SetHandler perl-script PerlHandler Apache::Registry Options ExecCGI PerlSendHeader On </Files>
A minimalist Perl program that demonstrates my problem is as follows:
#!perl print ("Content-type: text/html\n\n"); use strict; use vars qw($query $dsn $driver $db_username $db_password $dbh); require 5.006; $| = 1; ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); +($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; $CGI::POST_MAX = (1024 * 0); $CGI::DISABLE_UPLOADS = 1; $query = new CGI; use DBI(); $driver = "mysql"; $dsn = "DBI:$driver:database=shapeshifter;host=localhost;port=80"; $db_username = "nobody"; $db_password = ""; warn "Before DBI->connect(): [$$]"; $dbh = DBI->connect($dsn, $db_username, $db_password) or die sprintf " +Error: %s.\n", DBI->errstr; warn "After DBI->connect() [$$]"; my $sth = $dbh->prepare("SELECT * FROM frontpage"); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { print qq~Found a row: id = $ref->{'serial_number'}, name = $ref->{ +'position'}<BR>~; } $sth->finish(); $dbh->disconnect(); if ($ENV{'MOD_PERL'}) { print "Mod_perl is installed on this server: $ENV{'MOD_PERL'}<br>< +br>\n"; } else { print "Mod_perl is not installed on this server<br><br>\n"; }
The relevant output from "error.log" reads:
[Tue May 22 05:19:57 2001] nul: Before DBI->connect(): [2576] at e:/pa +d/htdocs/internet/system/db_test.pl line 20.<BR> [Tue May 22 05:19:58 2001] nul: DBI->connect failed: Can't connect to +MySQL server on 'localhost' (10061) at e:/pad/htdocs/internet/system/ +db_test.pl line 21<BR> [Tue May 22 05:19:58 2001] [error] Error: Can't connect to MySQL serve +r on 'localhost' (10061).
Can anyone tell me what's going wrong, before I tear out my few remaining strands of hair and go in search of a gun and belltower?
Thanks in advance
Edit: chipmunk 2001-05-22
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: mod_perl breaks MySQL connectivity...
by tye (Sage) on May 22, 2001 at 09:49 UTC | |
by shotgunefx (Parson) on May 22, 2001 at 13:16 UTC | |
by Hero Zzyzzx (Curate) on May 22, 2001 at 16:18 UTC | |
|
Re: mod_perl breaks MySQL connectivity...
by Odud (Pilgrim) on May 22, 2001 at 18:21 UTC | |
by DarkBlue (Sexton) on May 22, 2001 at 23:53 UTC |