I am using mod_perl for my web application. Currently, I plan to use a mysql database across the network. In every CGI request to display_customer_transaction.cgi, my script will
- Open up database connection across network
- Perform query on the database using SQL statement
- Analysis the data retrieved from database
- Print out the data in HTML format
- Close the database connection
After some profiling, I realize step (1) is the bottleneck. Hence, I wish to avoid opening and closing a database connection for every CGI request. My wish is, if my first CGI request opens up a database connection, my second incoming CGI request (from different client) may reuse the first database connection.
I tried to Google for "DBIX Persistent Database Connection" but hardly find relevant result. (Edit: that's because it's called DIBC, or DBIx::Class, not DBIX.)
I further find for relevant information, using Apache::DBI (However, my intention is on DBIX, not Apache::DBI). There are some information which confused me:
The Apache::DBI module still has a limitation: it keeps database connections persistent on a per process basis.
All the while, my concept on how Apache serving CGI request is that
- Apache will always spawn a new process to serve an incoming new CGI request. Whenever the Perl interpreter finish executed Perl script, the process will dead.
So, if Apache::DBI module only able to keeps database connections persistent on a per process basis, how can my second CGI request re-use back the connection opened by the first CGI request?
But come back to my original question. How can I have DBIX persistent database connection in mod_perl?