Short answer is "you can't really", at least for vanilla CGI. Every request that's dispatched by your CGI program is a separate process which services the request and then exits. Having said that, you do have options but they require more than just setting up a CGI does.
One option is to move to something like FastCGI or mod_perl, which keep a persistent perl interpreter around which can keep database connections around (see also Apache::DBI for the later).
Another is to use some form of connection caching in your database if it supports it (e.g. pgpool for Postgres).
The problem with these two approaches is that they may not be available if you're using some sort of vanilla lowest-common-denominator web hosting (although FastCGI does seem to be getting more support since Ruby on Rails can use it, so there may be hope).
In reply to Re: How to cache a socket in cgi programming?
by Fletch
in thread How to cache a socket in cgi programming?
by ablmf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |