ganeshk has asked for the wisdom of the Perl Monks concerning the following question:

I have a very basic question regarding Apache/mod_perl. I have a web
application running under mod_perl with Apache::DBI enabled that uses
mysql database. For certain kind of requests alone I want to enable
transaction at the beginning of the request and at the end of request,
commit and stop the transaction if the transaction was turned on.
All modules use the following code for getting database connections
$dbh = DBI->connect_cached($dsn, $user, $password, {RaiseError => 1, AutoCommit => $transaction });
Can I be sure that when a request is using such a transaction enabled
database connection handle, another request cannot get the same
transaction enabled database connection? As per the Apache::DBI
documentation, it only keeps connections persistent on a per process
basis. So I understand that the answer is yes, but just wanted to confirm
anyway.

Thanks very much

Replies are listed 'Best First'.
Re: Can one Apache process run multiple requests simultaneously?
by ikegami (Patriarch) on May 30, 2007 at 16:24 UTC

    In Apache 1.x, each Apache process handles only one request at a time, so there's no problem.

    In Apache 2.x, each Apache thread handles only one request at a time. *If* the cache is *not* shared among threads, there's no problem. I don't have access to CPAN here, so I can't check whether the cache is shared. It shouldn't be.

      Unless you're running on Windows, you should use the prefork MPM (i.e. not threads) with Apache 2 when running mod_perl. Threads use more memory than forked processes because of the way they are implemented in Perl.
      Thank you very much everyone for the help!!. The application runs on Apache 1.3 as of now and that is a good sign. But it was nice for all the inputs on Apache 2 also.
Re: Can one Apache process run multiple requests simultaneously?
by perrin (Chancellor) on May 30, 2007 at 16:48 UTC

    Yes, while it is possible to change the way Apache handles requests by using different MPMs, the standard MPMs for both unix and Windows will not try to process multiple requests from one process/thread.

    By the way, you don't really need to use connect_cached if you're using Apache::DBI. The normal connect and connect_cached both do the same thing when Apache::DBI is loaded.

      hi there... i'm running a pc and a server... in the server i have 4 virtual server which will reply upon receiving request from the pc... but the problem is, i can't run all 4 simultaneously... only 2 running and others waiting... once the first 2 done.. then only the last 2 running... i saw in the task bar there are 2 processes running with the name apache... i try stop 1.. then try again... now it's done 1 by one instead... i want to run all 4 at once simultaneously... what should i do? if there is a way to increase the number of process running as apache to be 4? plz help... ur replies are most appreciated... thanx... thibz
        This is not an Apache support forum. I'd suggest you ask for help on the apache-users mailing list.
Re: Can one Apache process run multiple requests simultaneously?
by InfiniteLoop (Hermit) on May 30, 2007 at 16:27 UTC
    ganeshk, you could have AutoCommit "ON" by default and for those transactions (before), turn it off and either "commit" or "rollback" the transaction. According to Apache::DBI's doc:
    ... However, because a connection may have set other parameters, the h +andle is reset to its initial connection state before it is returned +for a second time.