Just a thought. You may want to consider having the CGI process just queue a request to a daemon to prevent your server/database being overloaded by multiple simultaneous requests. You would simply do an insert into a request queue table with any necessary parameters, and have the daemon periodically check for new requests.
in reply to Re^2: Complete part of a cgi script before the rest
in thread Complete part of a cgi script before the rest