You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Zhuang <ch...@yahoo.com.au> on 2008/07/16 07:58:19 UTC
persistent database connection - Apache::DBI with mod_perl
Hi,
I have problems to setup persistent database connection for my perl project using mod_perl.
It tooks me two days which i still cann't figure out how mod_perl works with Apache::DBI.
My Server Settings:
ActiveState Perl 5.8.8 build 822
Apache HTTP Server 2.2.9
Apache DBI 1.06
mod_perl 2.03
DBD-Oracle 1.17
--------------Adding to httpd.conf--------------
LoadFile "C:/Perl/bin/perl58.dll"
LoadModule perl_module modules/mod_perl.so
PerlSetEnv DBI_TRACE "3=C:/Perl/dbitrace.log"
PerlModule Apache::DBI
PerlRequire "C:/Perl/lib/startup.pl"
--------------End-------------------------------------
--------------startup.pl--------------
#!c:/perl/bin/perl.exe
$ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!";
#use Apache::Registry;
use Apache::DBI;
use strict;
$Apache::DBI::DEBUG = 2;
Apache::DBI->connect_on_init("dbi:Oracle:host=xxx;sid=xxx",
"xxx", "xxx",
{PrintError => 1, RaiseError => 0, AutoCommit => 1,}
);
my $timeout = 0;
Apache::DBI->setPingTimeOut("dbi:Oracle:host=xxx;sid=xxx", $timeout);
1;
--------------End-------------------------------------
--------------Apache Startup Log-------------------------------------
[Wed Jul 16 14:43:54 2008] [notice] Apache/2.2.9 (Win32) mod_perl/2.0.3 Perl/v5.8.8 configured -- resuming normal operations
[Wed Jul 16 14:43:54 2008] [notice] Server built: Jun 13 2008 04:04:59
[Wed Jul 16 14:43:54 2008] [notice] Parent: Created child process 996
[Wed Jul 16 14:43:54 2008] [notice] Child 996: Child process is running
996 Apache::DBI PerlChildInitHandler
996 Apache::DBI need ping: yes
996 Apache::DBI new connect to 'host=xxx;sid=xxxxxxxxxAutoCommit=1PrintError=1RaiseError=0Username=xxx'
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Acquired the start mutex.
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Starting 64 worker threads.
[Wed Jul 16 14:43:55 2008] [notice] Child 996: Starting thread to listen on port 80.
--------------End-------------------------------------
I can see it sucessful open the oracle DB connection.
However, when I run an CGI script on the IE 6, it cannot find $ENV{MOD_PERL} and start new DBI connection.
--------foo.cgi--------------------
#!c:/perl/bin/perl.exe -d
use DBI;
use CGI qw(:standard);
my $dbh = DBI->connect("dbi:Oracle:host=xxx;sid=xxx",
"xxx", "xxx",
{PrintError => 1, RaiseError => 0, AutoCommit => 1,}
);
--------END--------------------
Do I need to do any setting in Apache for $ENV{MOD_PERL}?
Did I do any thing wrong in above code?
Thanks and Regards
Chris Z
Start at the new Yahoo!7 for a better online experience. www.yahoo7.com.au
Re: persistent database connection - Apache::DBI with mod_perl
Posted by Perrin Harkins <pe...@elem.com>.
On Wed, Jul 16, 2008 at 11:04 PM, Chris Zhuang <ch...@yahoo.com.au> wrote:
> But how to setup Komodo 3.1 to debug mod_perl?
You should probably ask the Komodo support list about that.
Apache::DB seems to be working.
- Perrin
Re: persistent database connection - Apache::DBI with mod_perl
Posted by Chris Zhuang <ch...@yahoo.com.au>.
Hi adam,
I got that mod_perl works on my server.
But how to setup Komodo 3.1 to debug mod_perl?
It seems like Komodo can only debug mod_cgi.
My httpd.conf setting:
<Perl>
use lib qw("C:/Program Files/ActiveState Komodo 3.1/dbgp/perllib");
$ENV{PERLDB_OPTS} = "RemotePort=127.0.0.1:1417 LogFile=stderr";
use Apache::DB ();
Apache::DB->init;
</Perl>
Alias /perl/ "C:/Apache2.2/htdocs/perl/"
<Location /perl/>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options +ExecCGI
PerlOptions +ParseHeaders
PerlFixupHandler Apache::DB
Order allow,deny
Allow from all
</Location>
Below is Apache error logs:
Thu Jul 17 12:50:21 2008] [error] Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. at C:/Perl/lib/Term/ReadKey.pm line 362.\nCompilation failed in require at C:/Perl/lib/Term/ReadLine/Perl.pm line 64.\n at C:/Perl/lib/Term/ReadLine/Perl.pm line 64\n\teval {...} called at C:/Perl/lib/Term/ReadLine/Perl.pm line 64\n\tTerm::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'IO::Socket::INET=GLOB(0xa4f9cbc)', 'IO::Socket::INET=GLOB(0xa4f9cbc)') called at C:/Perl/site/lib/Apache/perl5db.pl line 2226\n\tDB::setterm called at C:/Perl/site/lib/Apache/perl5db.pl line 773\n\tDB::DB called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\tModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdocs_perl_foo2_2ecgi::BEGIN() called at C:/Perl/lib/Term/ReadLine/readline.pm line 2\n\teval {...} called at C:/Perl/lib/Term/ReadLine/readline.pm line
2\n\teval 'package ModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdocs_perl_foo2_2ecgi;sub handler {local $0 = \\'C:/Apache2.2/htdocs/perl/foo2.cgi\\';\n#line 1 C:/Apache2.2/htdocs/perl/foo2.cgi\n#!c:/perl/bin/perl.exe\r\n use strict;\r\n print "Content-type: text/html\\\\n\\\\n";\r\n print "<HTML><BODY><H3>Environment variables</H3><UL>";\r\n foreach (sort keys %ENV) {\r\n my $val = $ENV{$_};\r\n $val =~ s|\\\\n|\\\\\\\\n|g;\r\n $val =~ s|"|\\\\\\\\"|g;\r\n print "<LI>$_ = \\\\"${val}\\\\"</LI>\\\\n";\r\n }\r\n #sleep(10);\r\n print "</UL></BODY></HTML>";\n}\n;' called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 677\n\tModPerl::RegistryCooker::compile('ModPerl::Registry=HASH(0x280c1ac)', 'SCALAR(0x1c615f0)') called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 406\n\tModPerl::RegistryCooker::convert_script_to_compiled_handler('ModPerl::Registry=HASH(0x280c1ac)') called at
C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 163\n\tModPerl::RegistryCooker::default_handler('ModPerl::Registry=HASH(0x280c1ac)') called at C:/Perl/site/lib/ModPerl/Registry.pm line 31\n\tModPerl::Registry::handler('ModPerl::Registry', 'Apache2::RequestRec=SCALAR(0x280c284)') called at C:/Perl/lib/Term/ReadLine/readline.pm line 2\n\teval {...} called at C:/Perl/lib/Term/ReadLine/readline.pm line 2\n at C:/Perl/lib/Term/ReadLine/Perl.pm line 64\n\tTerm::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'IO::Socket::INET=GLOB(0xa4f9cbc)', 'IO::Socket::INET=GLOB(0xa4f9cbc)') called at C:/Perl/site/lib/Apache/perl5db.pl line 2226\n\tDB::setterm called at C:/Perl/site/lib/Apache/perl5db.pl line 773\n\tDB::DB called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\tModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdocs_perl_foo2_2ecgi::BEGIN() called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\teval {...} called at C:/Apache2.2/htdocs/perl/foo2.cgi line
2\n\teval 'package ModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdocs_perl_foo2_2ecgi;sub handler {local $0 = \\'C:/Apache2.2/htdocs/perl/foo2.cgi\\';\n#line 1 C:/Apache2.2/htdocs/perl/foo2.cgi\n#!c:/perl/bin/perl.exe\r\n use strict;\r\n print "Content-type: text/html\\\\n\\\\n";\r\n print "<HTML><BODY><H3>Environment variables</H3><UL>";\r\n foreach (sort keys %ENV) {\r\n my $val = $ENV{$_};\r\n $val =~ s|\\\\n|\\\\\\\\n|g;\r\n $val =~ s|"|\\\\\\\\"|g;\r\n print "<LI>$_ = \\\\"${val}\\\\"</LI>\\\\n";\r\n }\r\n #sleep(10);\r\n print "</UL></BODY></HTML>";\n}\n;' called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 677\n\tModPerl::RegistryCooker::compile('ModPerl::Registry=HASH(0x280c1ac)', 'SCALAR(0x1c615f0)') called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 406\n\tModPerl::RegistryCooker::convert_script_to_compiled_handler('ModPerl::Registry=HASH(0x280c1ac)') called at
C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 163\n\tModPerl::RegistryCooker::default_handler('ModPerl::Registry=HASH(0x280c1ac)') called at C:/Perl/site/lib/ModPerl/Registry.pm line 31\n\tModPerl::Registry::handler('ModPerl::Registry', 'Apache2::RequestRec=SCALAR(0x280c284)') called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\teval {...} called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\nBEGIN failed--compilation aborted at C:/Apache2.2/htdocs/perl/foo2.cgi line 2.\n at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\teval 'package ModPerl::ROOT::ModPerl::Registry::C_3a_Apache2_2e2_htdocs_perl_foo2_2ecgi;sub handler {local $0 = \\'C:/Apache2.2/htdocs/perl/foo2.cgi\\';\n#line 1 C:/Apache2.2/htdocs/perl/foo2.cgi\n#!c:/perl/bin/perl.exe\r\n use strict;\r\n print "Content-type: text/html\\\\n\\\\n";\r\n print "<HTML><BODY><H3>Environment variables</H3><UL>";\r\n foreach (sort keys %ENV) {\r\n my $val = $ENV{$_};\r\n $val =~
s|\\\\n|\\\\\\\\n|g;\r\n $val =~ s|"|\\\\\\\\"|g;\r\n print "<LI>$_ = \\\\"${val}\\\\"</LI>\\\\n";\r\n }\r\n #sleep(10);\r\n print "</UL></BODY></HTML>";\n}\n;' called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 677\n\tModPerl::RegistryCooker::compile('ModPerl::Registry=HASH(0x280c1ac)', 'SCALAR(0x1c615f0)') called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 406\n\tModPerl::RegistryCooker::convert_script_to_compiled_handler('ModPerl::Registry=HASH(0x280c1ac)') called at C:/Perl/site/lib/ModPerl/RegistryCooker.pm line 163\n\tModPerl::RegistryCooker::default_handler('ModPerl::Registry=HASH(0x280c1ac)') called at C:/Perl/site/lib/ModPerl/Registry.pm line 31\n\tModPerl::Registry::handler('ModPerl::Registry', 'Apache2::RequestRec=SCALAR(0x280c284)') called at C:/Apache2.2/htdocs/perl/foo2.cgi line 2\n\teval {...}
I did a lot online search as well, but still cann't find a solution.
http://osdir.com/ml/ide.komodo.general/2005-07/msg00008.html
Regards
Chris Z
--- On Thu, 17/7/08, adam.prime@utoronto.ca <ad...@utoronto.ca> wrote:
From: adam.prime@utoronto.ca <ad...@utoronto.ca>
Subject: Re: persistent database connection - Apache::DBI with mod_perl
To: modperl@perl.apache.org
Received: Thursday, 17 July, 2008, 12:33 AM
Quoting Chris Zhuang <ch...@yahoo.com.au>:
> Hi,
> However, when I run an CGI script on the IE 6, it cannot find
> $ENV{MOD_PERL} and start new DBI connection.
> --------foo.cgi--------------------
> #!c:/perl/bin/perl.exe -d
> use DBI;
> use CGI qw(:standard);
>
> my $dbh = DBI->connect("dbi:Oracle:host=xxx;sid=xxx",
> "xxx", "xxx",
> {PrintError => 1, RaiseError => 0,
> AutoCommit => 1,}
> );
> --------END--------------------
>
It looks like your CGI's are are running under CGI, not
ModPerl::PerlRun, or ModPerl::Registry.
see:
http://perl.apache.org/docs/2.0/user/intro/start_fast.html#Registry_Scripts
Start at the new Yahoo!7 for a better online experience. www.yahoo7.com.au
Re: persistent database connection - Apache::DBI with mod_perl
Posted by ad...@utoronto.ca.
Quoting Chris Zhuang <ch...@yahoo.com.au>:
> Hi,
> However, when I run an CGI script on the IE 6, it cannot find
> $ENV{MOD_PERL} and start new DBI connection.
> --------foo.cgi--------------------
> #!c:/perl/bin/perl.exe -d
> use DBI;
> use CGI qw(:standard);
>
> my $dbh = DBI->connect("dbi:Oracle:host=xxx;sid=xxx",
> "xxx", "xxx",
> {PrintError => 1, RaiseError => 0,
> AutoCommit => 1,}
> );
> --------END--------------------
>
It looks like your CGI's are are running under CGI, not
ModPerl::PerlRun, or ModPerl::Registry.
see:
http://perl.apache.org/docs/2.0/user/intro/start_fast.html#Registry_Scripts