From: ahoward Date: 2003-01-24T09:05:42+09:00 Subject: Re: mod_ruby: what's persistent and what's shared? On Fri, 24 Jan 2003, Bill Kelly wrote: > Hi, > > From: "Ollivier Robert" > > > > Imagine you do something like this in your httpd.conf > > > > -=-=- > > RubyRequire common-data > > -=-=- > > > > and that in common-data.rb you have this: > > > > -=-=- > > require 'dbi' > > > > $DB = DBI.connect("dbi:mysql:foodb", "user", "password") > > -=-=- > > > > Will all instances of httpd share the same $DB ? Remember that it is not > > data created by a script or a .rhtml page, it is data created when you > > start the httpd server... > > My guess is that this would be problematic. Forked children > do inherit copies of the parent's file handles (I'm assuming > a DB connection is at its heart a file handle / socket?) > > My guess as to what would happen would be that the child http > processes would indeed probably "share the same $DB", assuming > the http.conf processing happens before the children are forked. > > However, I think it would likely be a problem to have the > child processes all chattering simultaneously at the DB over > the same connection. I wouldn't expect that to work properly. > (But I don't know how it's implemented, so I could be wrong.) that approach also makes me queasy... why not simple make a little drb conection pool? that'd be pretty trival to implement and neatly solves the problem externally to the web server and individual cgi scripts? i've actually be working on a CGI::Cache for such purposes... it would be just like a session but able so contain 'live' objects, like database handles. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================