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

Hi, how i can effectively share open DB handler (DBD::mysql) among forked processes?
  • Comment on Sharing DB handler among forked processes

Replies are listed 'Best First'.
Re: Sharing DB handler among forked processes
by kyle (Abbot) on Aug 12, 2007 at 01:47 UTC

    Basically, you can't, but see DBI, fork, and clone. (Also, we might be better able to help you if you tell us what you're really trying to do.)

      I write web spider which grab info about auction bids. Bids are grouped by sections. So i fork each section, collect information for it and try to insert this info into DB. Maybe i don't need shared DB handler but must create new handler for each forked process?

        Yes, you don't need a shared DB handle. Each forked process can have its own connection to the database and operate on it through that connection. From your description, they don't even need to talk to each other, so you don't need any other IPC. The database shouldn't have any problem dealing with the data coming from different directions at once.

        Share the scraped info with a master proc using shmem, or sockets. Then have the parent inject the data into the DB.


        Evan Carroll
        www.EvanCarroll.com