From: Thilo Planz <suppressed>
> > If this is correct, won't mod_perl execute
> > cgiapp_init multiple times? My variables will be re-initialized when
> > that
> > may not be what I want?
>
> Yes, cgiapp_init is run for every request.
> Using plain CGI that makes no difference, but using mod_perl you
> probably do not want to re-open DB connections, or read config files
> all the time.
>
> So what I usually do here is make packages that handle stuff I want to
> set up once and then persist.
> For example:
>
> package MyDB;
> use DBI;
> our $_conn;
> sub conn(){
> return $_conn if $_conn;
> return $_conn = DBI->connect ( ..... );
> }
>
> With this code, I can just call MyDB::conn() whenever I need a database
> connection. It will be established only once, and then reused.
> And this code runs unmodified (and does the right thing) under CGI,
> mod_perl or in command line tools.
Is there anything else other than database connections that you are worried
about? If that is all then you won't need to worry about it. Under CGI and
command line you will need to open those database connections everytime it
runs anyway and under mod_perl if you use Apache::DBI then it will
transparently cache your database connections without you having to change one
piece of your code. Admittedly if you're doing more than just managing db
connections in this init package then go ahead.
Michael Peters
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.