You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Maikel Punie <ma...@gmail.com> on 2007/06/09 09:12:45 UTC

mod vhost sql

hey,

I'm trying to write a mod_vhost_mysql, but this time one that can get
all the data from the mysql db, and not just the docroot.

So basically for every request the ap_hook_translate_name() is called to
handle the function inside my module.
at the moment for every request thats done the modules does the following:
1- create a db connection
2- do the sql query
3- parse results
4- close db
5- return OK

basically this isn't really nice to handle, creating a db connection and
closing it for every request will create an enormous pressure on the
mysql db server.
So now the question, is there a hook (or hooks) that is defined so i can
call it,
1- just before the server actually starts running (after config parsing
i guess)
2- just before the server stops running

this way i could open up the db connection with hook one, and close it
with hook two, this will decrease the load on the db server.

Maikel




Re: mod vhost sql

Posted by Nick Kew <ni...@webthing.com>.
On Sat, 09 Jun 2007 09:12:45 +0200
Maikel Punie <ma...@gmail.com> wrote:

> hey,
> 
> I'm trying to write a mod_vhost_mysql, but this time one that can get
> all the data from the mysql db, and not just the docroot.

All what data?  Do you mean every apache directive, including
those implemented by third-party modules, should work in SQL?
If so, take a look at mod_macro, which gives you the crux of
the matter: namely a module feeding configuration to other
modules.

Also, please get MySQL out of your mindset here.  You should
the Apache DBD framework, so your module supports other
database backends automatically.

> So basically for every request the ap_hook_translate_name() is called
> to handle the function inside my module.

Now I'm confused.  *what* is the scope of this module?

> at the moment for every request thats done the modules does the
> following: 1- create a db connection
> 2- do the sql query
> 3- parse results
> 4- close db
> 5- return OK
> 
> basically this isn't really nice to handle, creating a db connection
> and closing it for every request will create an enormous pressure on
> the mysql db server.

That's another reason to use mod_dbd.

> So now the question, is there a hook (or hooks) that is defined so i
> can call it,
> 1- just before the server actually starts running (after config
> parsing i guess)

Yes.

> 2- just before the server stops running

No.  Use a pool cleanup.

> this way i could open up the db connection with hook one, and close it
> with hook two, this will decrease the load on the db server.

That's been a solved problem since mod_perl gave us the architecture
now known as LAMP, back in '95 (or was it '96?).  In the intervening
years we've moved on, and DBD solves two major issues you'll still
have if you just make the changes you're asking about here.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Re: mod vhost sql

Posted by Issac Goldstand <ma...@beamartyr.net>.
Maikel Punie wrote:
> hey,
>
> I'm trying to write a mod_vhost_mysql, but this time one that can get
> all the data from the mysql db, and not just the docroot.
>   
> So basically for every request the ap_hook_translate_name() is called to
> handle the function inside my module.
> at the moment for every request thats done the modules does the following:
> 1- create a db connection
> 2- do the sql query
> 3- parse results
> 4- close db
> 5- return OK
>
> basically this isn't really nice to handle, creating a db connection and
> closing it for every request will create an enormous pressure on the
> mysql db server.
>   
you're correct :)
> So now the question, is there a hook (or hooks) that is defined so i can
> call it,
> 1- just before the server actually starts running (after config parsing
> i guess)
>   
post_config
> 2- just before the server stops running
>
>   
Don't worry about this.  Tie a cleanup function to the config pool and
it'll do it for you.  But why do you need to keep the handle open the
entire time in the first place?  Just add the mysql data to the config
tree and clean up immediately...

  Issac