in reply to perl_mod caching DBI responses

However, whenever I try to run it via mod_perl, it appears that the DBI responses are being cached in a mod_perl thread (or whatever it uses). This is a bad thing. FWIW, using (or not using) Apache::DBI doesn't make a difference.

This "Bad Thing" (which it is not) comes forth from not using strict, and more directly from using global variables. With mod_perl, global variables are persistent for the interpreter is embedded in Apache itself and will not exit until Apache exits. When programming for mod_perl, ALWAYS use strict! (Actually, remove "When programming for mod_perl, " and just always use strict.)

You can't get away with sloppy programming in mod_perl. Find more information about mod_perl before doing anything with it, as incorrect use may fry your Apache.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: perl_mod caching DBI responses
by fuzzyping (Chaplain) on Jul 02, 2002 at 14:40 UTC
    Thanks Juerd! Yes, this fixed everything. I was not aware of that problem with globals and mod_perl. First, I was mistaken in thinking I *was* using strict properly. I was actually calling it from the base cgi, rather than the package (and assuming it would affect both). :-(

    Second, I did not mean to let those few globals slide through. Because I accidentally wasn't using strict correctly (this is the first package I've ever written), I wasn't getting any scoping errors... as you can see by the rest of my code, I made an honest attempt at scoping properly.

    Anyhoo, thanks again! w00t!!!

    -fuzzyping
      I was just about to post a list of globals in your code, but I see you've already got it covered. Congrats on getting it working, and improving your coding style.

      You can read about issues with globals and other things in the mod_perl guide. By the way, this is what I meant about possibly using Apache::PerlRun instead of Apache::Registry. Apache::PerlRun will clear globals, which would have made your code work, but it's not as fast because of this.