[OT] Persistant MySQL connections in Apache 2
This is really a C API thing, but I was wondering if Apache2::DBI people can help me shed some light on this... - Original Message - From: Kent Fitch To: [EMAIL PROTECTED] Sent: Monday, November 18, 2002 5:37 AM Subject: Re: [apache-modules] Persistant MySQL connections in Apache 2 Hi Issac, From: Issac Goldstand Subject: [apache-modules] Persistant MySQL connections in Apache 2 Hi all, I'm a rookie C API programmer (mod_perl was just so much *easier* most of the time :-)), and am working on coding a module to with in my front-end Apache 2/mod_proxy server. The idea of the module is to provide access to the front-end server with a list of blacklisted IPs which are stored in a MySQL database. So I'm thinking the module's child_init should open the connection to the MySQL database and then the access_handler can grab the MySQL connection from the child-pool. Yes, but beware that in a threaded Apache run-time, there could be many threads fo execution processing many requests simultaneously in your child process, so you'll have to arrange to lock the connection whilst a thread is using it and possibly have a pool of them. See Thread Safety http://httpd.apache.org/docs-2.0/developer/thread_safety.html But the problem is that I would *like* for the connections to the database be closed before the pool is simply swept clean upon destruction. I would think that that would be a good thing to do - maybe I'm wrong... Yes - you should register a cleanup function on the pool you allocate the data structures for the connection(s) from in your init. See these notes on pooling (which may be a bit 1.3-ish and hence out of date, but the ideas are relevant): http://httpd.apache.org/docs-2.0/developer/API.html#pools and see the apr_pool_cleanup_register api Kent Fitch
Re: New module : Apache::Session::Manager
On 16 Nov 2002 13:24:13 +0200 Clinton Gormley [EMAIL PROTECTED] wrote: I've written a new module as a wrapper around Apache::Session which provides short term (ie session) tracking (which is something that Apache::SessionManager and Apache::SessionX provide), but this adds long term user tracking, and methods to aid login, logout etc. I would appreciate feedback, not least of all, what it should be called! Apache::SessionManager exists already, and I realise that calling this module Apache::Session::Manager will cause confusion, so please... Dear Clinton, I think that the name you've chosen (Apache::Session::Manager) is wrong :-( not because it will cause confusion with my Apache::SessionManager module, but because Apache::Session::* namespace is informally reserved to Apache::Session sub components like data storage, serializers or ID generators. Your (and my, of course) session manager module hasn't any relationships with these. This name adds only a little bit of confusion on wrong (historically) Apache::Session namespace - there is a direct tie between Apache::Session and mod_perl? ;-) When I started with my little project I've first searched on CPAN and the most similar module I founded was the AxKit-XSP-Session. Unfortunately this is a session manager plugin for AxKit and my goal was to develope a module with no glue with other applications server that the mod_perl itself. Then I've chosen Apache::SessionManager (I've discarded Apache::Session::Manager name, of course) but before putting the first line of code on CPAN, I have sended various RFCs to mod_perl and [EMAIL PROTECTED] mailing lists, to comp.lang.perl.misc and comp.lang.perl.modules: this is the standard way to contribute to CPAN. See ml/news archives for the complete threads [...] I have done a (very) quick look to your code and I've seen some likeness with Apache::AuthCookie and/or Apache-AxKit-Plugin-Session. If you were doing something like this, you could probably start with one of the Auth* modules, which already do a good job of handling things. I am also working to add this features not to my module but adding session management in Apache::AuthCookie! Moreover, I agree about a possibility of the integration with your additional features into my Apache::SessionManager. Regards - Enrico
Re: New module : Apache::Session::Manager
Hi Enrico After posting, I looked at Apache::AuthCookie for the first time - don't why I hadn't looked at it before - to find that I was, indeed, duplicating a lot of work that has been done before. Didn't I feel foolish! It looks like Perrin may have to write a ...why not to write your own session manager article... to compliment his Templating article. Apologies for this. I'll haul my sorry ass back to my machine now. Clint
What triggers the User Handler?
When a request is made I thought each of the 11 or so handlers runs and that's it. I'm seeing some behaviour where a homepage is loaded but the user handler that I designated seems to run several times (I have some print statements that print to a file), but I'm only loading one webpage. It doesn't have any frames. What's going on?
Re: timing downloads with mod_perl
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - -- Nick [EMAIL PROTECTED] wrote: I would like to log the time it take users to download items from my site. Has anyone has any success writing a mod perl prog to accomplish this? create two handlers: - One in PerlInithandler - The second in PerlLogHandler (or similar) Use Time::HiRes to get the time in high resolution In InitHandler: get the time the request starts. In LogHandler: look how many time the request took. But normaly your server's OS caches the output, so this might be only a hint for big files or the time taken by the request. For complete HTML pages you can write some JavaScript ... HTH, Alvar - -- ** Alvar C.H. Freude ** http://alvar.a-blast.org/ == NEU! ** ** http://odem.org/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE92R9lOndlH63J86wRAgjaAJ9RN6BISP5lf0QxFWYj8qLh7en/jQCgzNNE Qds7SV+WQ/I0giIfi00a8lA= =brMe -END PGP SIGNATURE-
Re: configuration table permanent storage?
Marc Murphy wrote: Once you use a configuration directive to store some values in a module's configuration table, is there any way to change them after that? When there is a request I grab the values I initally stored in the configuration table (which I believe are stored only once when httpd starts and the configuration directive is encountered) I grab the values using $cfg= $r-Apache::ModuleConfig($r, Modulename). per-directory configuration directives are run (at least) once per request, so it really depends on the placement of your directives. see the diagram in the introduction to part III in the cookbook for some details. http://www.modperlcookbook.org/chapters/part3.pdf Now if I make some changes i.e. $cfg-{key}=newvalue that's fine for the request currently going on. Then for the next request the newvalue is replaced by the initial value. Is this how it's supposed to work...i.e. the way you setup the module's config table is permanent? yes. it's exactly like you made the entry in httpd.conf. Can I get the change to stick somehow? not that I'm aware of at the moment. HTH --Geoff
Re: What triggers the User Handler?
Richard Clarke wrote: Marc, If the webpage has images then a request will be made for each of these images as well. Depending on your configuration this could account for it being run several times. not to mention subrequests, such as a request for foo.com/bar that gets translated into foo.com/bar/ --Geoff
RE: What triggers the User Handler?
as well as $r-push_handlers and $r-set_handlers and PerlHandler YourHandler in httpd.conf -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.
mp2.0 w/Apache 2.0, DBI setup??
I am having difficulty getting Apache 2.0.43, perl 5.6.1, and mod_perl 1.99_07 to work together. Trying to authenticate users based on a MySQL table. All compiles and installs. I installed Apache-DBI-0.89 perl module. In configuring, I keep getting Seg faults. Can someone let me know if I am even setting up the config file correctly for Apache. Seems I have searched all the archives, and keep getting conflicting information... In httpd.conf --- ADDED THE FOLLOWING LoadModule perl_module modules/mod_perl.so PerlRequire /home/apps/httpd-2.0.43/perl/startup.pl #PerlModule Apache2 PerlModule Apache::DBI #PerlModule Apache::AuthDBI My startup.pl files looks like: use Apache2 (); use lib qw(/home/apps/httpd-2.0.43/perl); # enable if the mod_perl 1.0 compatibility is needed use Apache::compat (); use ModPerl::Util (); #for CORE::GLOBAL::exit use Apache::RequestRec (); use Apache::RequestIO (); use Apache::RequestUtil (); use Apache::Server (); use Apache::ServerUtil (); use Apache::Connection (); use Apache::Log (); use APR::Table (); use ModPerl::Registry (); use Apache::Const -compile = ':common'; use APR::Const -compile = ':common'; 1; --- Did I miss something obvious? When I start apache, it seg faults. Commenting out all the PerlModule defs in httpd.conf allows the server to start? How can you get the compat mode working with the DBI modules, or do we even need the compat mod_perl modules? If All seems correct, then I will recompile everything with debugging!! Robert
Re: mp2.0 w/Apache 2.0, DBI setup??
On Mon, 18 Nov 2002, Robert Kohler wrote: I am having difficulty getting Apache 2.0.43, perl 5.6.1, and mod_perl 1.99_07 to work together. Trying to authenticate users based on a MySQL table. All compiles and installs. I installed Apache-DBI-0.89 perl module. In configuring, I keep getting Seg faults. Can someone let me know if I am even setting up the config file correctly for Apache. Seems I have searched all the archives, and keep getting conflicting information... Are you using the latest versions of DBI and DBD::mysql? If not, does this still happen with the latest versions? -- best regards, randy kobes
Re: mp2.0 w/Apache 2.0, DBI setup??
Randy Kobes wrote: On Mon, 18 Nov 2002, Robert Kohler wrote: I am having difficulty getting Apache 2.0.43, perl 5.6.1, and mod_perl 1.99_07 to work together. Trying to authenticate users based on a MySQL table. All compiles and installs. I installed Apache-DBI-0.89 perl module. In configuring, I keep getting Seg faults. Can someone let me know if I am even setting up the config file correctly for Apache. Seems I have searched all the archives, and keep getting conflicting information... Are you using the latest versions of DBI and DBD::mysql? If not, does this still happen with the latest versions? DBI 1.21 DBD::mysql 2.0.11 Note the most current, but I can't modify this as it is in production currently. I can try testing on a completely different system if need be.
Re: [OT] Persistant MySQL connections in Apache 2
Issac Goldstand wrote: This is really a C API thing, but I was wondering if Apache2::DBI people can help me shed some light on this... I'm not sure what's the Apache2::DBI question, but we (Tim, Hugo, Eric at el.) have discussed the Apache::DBI for threaded apps at the last TPC and the conclusion was that we need to write a generic Perl Thread::DBI module to work with threaded Perl and then use Apache::DBI on top of it. Some of this was discussed on the dbi-dev list, but as far as I know nothing was developed so far. If you want to discuss the design, which is not trivial, and implementation, it's probably the best to do that on the dbi-dev list. - Original Message - From: Kent Fitch To: [EMAIL PROTECTED] Sent: Monday, November 18, 2002 5:37 AM Subject: Re: [apache-modules] Persistant MySQL connections in Apache 2 Hi Issac, From: Issac Goldstand Subject: [apache-modules] Persistant MySQL connections in Apache 2 Hi all, I'm a rookie C API programmer (mod_perl was just so much *easier* most of the time :-)), and am working on coding a module to with in my front-end Apache 2/mod_proxy server. The idea of the module is to provide access to the front-end server with a list of blacklisted IPs which are stored in a MySQL database. So I'm thinking the module's child_init should open the connection to the MySQL database and then the access_handler can grab the MySQL connection from the child-pool. Yes, but beware that in a threaded Apache run-time, there could be many threads fo execution processing many requests simultaneously in your child process, so you'll have to arrange to lock the connection whilst a thread is using it and possibly have a pool of them. See Thread Safety http://httpd.apache.org/docs-2.0/developer/thread_safety.html But the problem is that I would *like* for the connections to the database be closed before the pool is simply swept clean upon destruction. I would think that that would be a good thing to do - maybe I'm wrong... Yes - you should register a cleanup function on the pool you allocate the data structures for the connection(s) from in your init. See these notes on pooling (which may be a bit 1.3-ish and hence out of date, but the ideas are relevant): http://httpd.apache.org/docs-2.0/developer/API.html#pools and see the apr_pool_cleanup_register api Kent Fitch -- _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: mp2.0 w/Apache 2.0, DBI setup??
Robert Kohler wrote: Randy Kobes wrote: On Mon, 18 Nov 2002, Robert Kohler wrote: I am having difficulty getting Apache 2.0.43, perl 5.6.1, and mod_perl 1.99_07 to work together. Trying to authenticate users based on a MySQL table. All compiles and installs. I installed Apache-DBI-0.89 perl module. In configuring, I keep getting Seg faults. Can someone let me know if I am even setting up the config file correctly for Apache. Seems I have searched all the archives, and keep getting conflicting information... Are you using the latest versions of DBI and DBD::mysql? If not, does this still happen with the latest versions? DBI 1.21 DBD::mysql 2.0.11 Note the most current, but I can't modify this as it is in production currently. I can try testing on a completely different system if need be. As Randy has mentioned you need DBI-1.30 and your problem should go away. It did for me :) -- _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com http://singlesheaven.com http://perl.apache.org http://perlmonth.com/