in reply to Re: Net::Server and DBI
in thread Net::Server and DBI

zwon,

I guess what I'm not sure about is, if I put the DBI->connect() call before process_request() then will it still be part of the child, or will it belong to the parent?

use base qw(Net::Server::PreFork); MyPackage->new({conf_file => '/home/aaron/serv.conf',})->run; //does $dbh belong to the parent? $dbh = DBI->connect("DBI:mysql:$DSN", $user, $password); sub process_request { //do child stuff here }

As for why I chose to use Net::Server, it seemed easy and reliable. And it is so far. This is my first issue with it directly and I'm nearly done with my app. I'm just trying to make things more efficient, like not having to establish a database connection for each socket connection. I want the sockets to come and go, while I maintain a single DB connection per process.

Replies are listed 'Best First'.
Re^3: Net::Server and DBI
by zwon (Abbot) on May 21, 2009 at 18:01 UTC

    Yes, post_accept and process_request are executed by the same process. Here's the sample that demonstrates this:

    use strict; use warnings; MyServer->run(port => 7777); package MyServer; use base qw(Net::Server::PreFork); sub post_accept { warn "post accept in $$\n"; } sub process_request { warn "process request in $$\n"; } __END__ ... post accept in 9238 process request in 9238 post accept in 9241 process request in 9241 post accept in 9242 process request in 9242