You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Vladimir S. Tikhonjuk" <vs...@vst.donetsk.ua> on 2006/08/01 12:25:03 UTC
Apache::DBI->connect_on_init
Hi all!
There are some problem with subj :)
I made Apache-DBI-startup.pl script:
# BEGIN Apache-DBI-startup.pl
Apache::DBI->connect_on_init(
'dbi:Pg:dbname=database;host=database',
'user',
'password',
{
PrintError => 1,
RaiseError => 1,
AutoCommit => 0
}
);
1;
# END Apache-DBI-startup.pl
Then, in httpd.conf:
#------ BEGIN part of httpd.conf
PerlModule Apache::DBI
PerlRequire "/etc/apache2/modules.d/Apache-DBI-startup.pl"
#------ END part of httpd.conf
bash # /etc/init.d/apache start ERROR
bash # tail /var/log/apache/error_log
[Tue Aug 01 13:21:23 2006] [error] Can't locate object method
"connect_on_init" via package "Apache::DBI" (perhaps you forgot to load
"Apache::DBI"?) at /etc/apache2/modules.d/Apache-DBI-startup.pl line
1.\nCompilation failed in require at (eval 5) line 1.\n
[Tue Aug 01 13:21:23 2006] [error] Can't load Perl file:
/etc/apache2/modules.d/Apache-DBI-startup.pl for server
pluton.upts.promtelecom:0, exiting...
Well, when I put "use Apache::DBI" into Apache-DBI-startup.pl script -
no errors.
But I don't see any connections to the Database. I think, that If I use
connect_on_init and have for example 5 apache processes, after starting
of apache I will get 5 database connections.
Best regards,
Vladimir S. Tikhonjuk
Re: Apache::DBI->connect_on_init
Posted by Jonathan Vanasco <jo...@2xlp.com>.
On Aug 1, 2006, at 6:25 AM, Vladimir S. Tikhonjuk wrote:
> Well, when I put "use Apache::DBI" into Apache-DBI-startup.pl script -
> no errors.
Because you need to import Apache::DBI before you call any of its
methods- same as any other perl script.
> But I don't see any connections to the Database. I think, that If I
> use
> connect_on_init and have for example 5 apache processes, after
> starting
> of apache I will get 5 database connections.
That is the expected behavior.
connect_on_init connects on each child process initialization-- you
get 1 db handle per apache child.
If you have 5 apache processes and connect 10 times, you will only be
sharing 5 handles- one per child.
connect_on_init does not share 1 db handle for all apaches. that
would be a logistical nightmare, and your system would not work.