You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jiri Pavlovsky <ji...@getnet.cz> on 2010/04/17 21:27:40 UTC

Apache::DBI connect_on_init problem

Hello,

I'm trying to prestart db connection. But Apache::DBI->connect_on_init 
is not working. Gives no error, but db connection is not made.
Setting $Apache::DBI::DEBUG = 2 indicates that ChildInitHandler runs.

I tried to create my custom ChildInitHandler and start db connection 
from it but it also has no effect.
It also seems as if the handler was silently aborted after the connect call.
I inserted debugging print before and after the connect call. In the 
Postgres log I can see a connection made and immediately terminated.


So now I'm quite helpless as what to do.

Re: Apache::DBI connect_on_init problem

Posted by Fred Moyer <fr...@redhotpenguin.com>.
On Sat, Apr 17, 2010 at 1:09 PM, Jiri Pavlovsky <ji...@getnet.cz>
wrote:>  Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
>    "user",
>    "pass",
>    {
>      PrintError => 1, # warn() on errors
>      RaiseError => 0, # don't die on error
>      AutoCommit => 1, # commit executes immediately
>      pg_enable_utf8 => 1,
>    }
>  );
>
>  Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
>    "another",
>    "pass",
>    {
>      PrintError => 1, # warn() on errors
>      RaiseError => 0, # don't die on error
>      AutoCommit => 1, # commit executes immediately
>      pg_enable_utf8 => 1,
>    }
>  );

Why do you call connect_on_init twice with different parameters?  If
anything stands out as causing the problem, that would come to my mind
as the first thing.

Re: Apache::DBI connect_on_init problem

Posted by Jiri Pavlovsky <ji...@getnet.cz>.
On 17.4.2010 23:21, Jiri Pavlovsky wrote:
> On 17.4.2010 22:42, Chris Bennett wrote:
>>
>> Oh, this is your error. You may only use Apache::DBI_connect_on_init for
>> ONE connection, which stays up and running. Use your more important one
>> (for speed) for this.
>
>
>
> This doesn't seem to make difference. It doesn't work even when making
> only one connection. The connection is not made.
>
> I wanted to make two, because I have two apps. One is frequently used
> and so the db connection is made from the app short after spawning the
> child anyway.
>
> The other one is seldom so there is a overhead every time request comes.
>
> What seems to work though is to create both connection sin the first app.
>

UPDATE: My problem was solved by upgrading Apache::DBI to 1.08. Yes, I 
should have done that first.
I can even make two connections from startup.pl.




Re: Apache::DBI connect_on_init problem

Posted by Jiri Pavlovsky <ji...@getnet.cz>.
On 17.4.2010 22:42, Chris Bennett wrote:
>
> Oh, this is your error. You may only use Apache::DBI_connect_on_init for
> ONE connection, which stays up and running. Use your more important one
> (for speed) for this.



This doesn't seem to make difference. It doesn't work even when making 
only one connection. The connection is not made.

I wanted to make two, because I have two apps. One is frequently used 
and so the db connection is made from the app short after spawning the 
child anyway.

The other one is seldom so there is a overhead every time request comes.

What seems to work though is to create both connection sin the first app.




Re: Apache::DBI connect_on_init problem

Posted by Perrin Harkins <ph...@gmail.com>.
On Sat, Apr 17, 2010 at 4:42 PM, Chris Bennett
<ch...@bennettconstruction.biz> wrote:
> You may also have other connections, but these will reconnect-disconnect
> each time

For the record, Apache::DBI will work with any number of connections,
keeping them persistent.  It's also correct to call connect_on_init
multiple times.  It just pushes the parameters onto a list of
connections to open.

> tack in a dbi_connect_method => 'connect'  for these other ones

You can do that for connections that you don't want to be persistent.

- Perrin

Re: Apache::DBI connect_on_init problem

Posted by Chris Bennett <ch...@bennettconstruction.biz>.
On 04/17/10 15:09, Jiri Pavlovsky wrote:
> On 17.4.2010 22:22, Chris Bennett wrote:
>> On 04/17/10 14:27, Jiri Pavlovsky wrote:
>>> Hello,
>>>
>>> I'm trying to prestart db connection. But Apache::DBI->connect_on_init
>>> is not working. Gives no error, but db connection is not made.
>>> Setting $Apache::DBI::DEBUG = 2 indicates that ChildInitHandler runs.
>>>
>>> I tried to create my custom ChildInitHandler and start db connection
>>> from it but it also has no effect.
>>> It also seems as if the handler was silently aborted after the connect
>>> call.
>>> I inserted debugging print before and after the connect call. In the
>>> Postgres log I can see a connection made and immediately terminated.
>>>
>>>
>>> So now I'm quite helpless as what to do.
>>>
>>
>> I use Apache::DBI and connect_on_init.
>> What are your full details? Using startup.pl?
>> what values for initial connection?
>
>
>
> Hello,
>
> my start-up.pl below. I try to setup two connections.
>
> In Apache log I see several lines like:
> 13121 Apache::DBI PerlChildInitHandler
> 13121 Apache::DBI push PerlChildExitHandler
>
> No errors. But in Postgres log I can see several very short connections
> as the first user. So maybe it is connecting and then it quits?
>
> Thats all I could find out.
>
> Thanks
>
>
>
> ----------------------------------------------
>
>
>
> #!/usr/bin/perl -w
>
>
>
> use strict;
> use Apache::DBI;
>
> $Apache::DBI::DEBUG = 2;
>
> DBI->install_driver("Pg");
>
>
>
>
> Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
> "user",
> "pass",
> {
> PrintError => 1, # warn() on errors
> RaiseError => 0, # don't die on error
> AutoCommit => 1, # commit executes immediately
> pg_enable_utf8 => 1,
> }
> );
>
> Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
> "another",
> "pass",
> {
> PrintError => 1, # warn() on errors
> RaiseError => 0, # don't die on error
> AutoCommit => 1, # commit executes immediately
> pg_enable_utf8 => 1,
> }
> );
>
>

Oh, this is your error. You may only use Apache::DBI_connect_on_init for 
ONE connection, which stays up and running. Use your more important one 
(for speed) for this.

You may also have other connections, but these will reconnect-disconnect 
each time

Use the following for those:

tack in a dbi_connect_method => 'connect'  for these other ones

Re: Apache::DBI connect_on_init problem

Posted by Jiri Pavlovsky <ji...@getnet.cz>.
On 17.4.2010 22:22, Chris Bennett wrote:
> On 04/17/10 14:27, Jiri Pavlovsky wrote:
>> Hello,
>>
>> I'm trying to prestart db connection. But Apache::DBI->connect_on_init
>> is not working. Gives no error, but db connection is not made.
>> Setting $Apache::DBI::DEBUG = 2 indicates that ChildInitHandler runs.
>>
>> I tried to create my custom ChildInitHandler and start db connection
>> from it but it also has no effect.
>> It also seems as if the handler was silently aborted after the connect
>> call.
>> I inserted debugging print before and after the connect call. In the
>> Postgres log I can see a connection made and immediately terminated.
>>
>>
>> So now I'm quite helpless as what to do.
>>
>
> I use Apache::DBI and connect_on_init.
> What are your full details? Using startup.pl?
> what values for initial connection?



Hello,

my start-up.pl below. I try to setup two connections.

In Apache log I see several lines like:
13121 Apache::DBI             PerlChildInitHandler
13121 Apache::DBI             push PerlChildExitHandler

No errors. But in Postgres log I can see several very short connections 
as the first user. So maybe it is connecting and then it quits?

Thats all I could find out.

Thanks



----------------------------------------------



#!/usr/bin/perl -w



use strict;
use Apache::DBI;

$Apache::DBI::DEBUG = 2;

DBI->install_driver("Pg");




   Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
     "user",
     "pass",
     {
       PrintError => 1, # warn() on errors
       RaiseError => 0, # don't die on error
       AutoCommit => 1, # commit executes immediately
       pg_enable_utf8 => 1,
     }
   );

   Apache::DBI->connect_on_init("dbi:Pg:dbname=p69",
     "another",
     "pass",
     {
       PrintError => 1, # warn() on errors
       RaiseError => 0, # don't die on error
       AutoCommit => 1, # commit executes immediately
       pg_enable_utf8 => 1,
     }
   );


Re: Apache::DBI connect_on_init problem

Posted by Chris Bennett <ch...@bennettconstruction.biz>.
On 04/17/10 14:27, Jiri Pavlovsky wrote:
> Hello,
>
> I'm trying to prestart db connection. But Apache::DBI->connect_on_init
> is not working. Gives no error, but db connection is not made.
> Setting $Apache::DBI::DEBUG = 2 indicates that ChildInitHandler runs.
>
> I tried to create my custom ChildInitHandler and start db connection
> from it but it also has no effect.
> It also seems as if the handler was silently aborted after the connect
> call.
> I inserted debugging print before and after the connect call. In the
> Postgres log I can see a connection made and immediately terminated.
>
>
> So now I'm quite helpless as what to do.
>

I use Apache::DBI and connect_on_init.
What are your full details? Using startup.pl?
what values for initial connection?