This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
To: "modperl@apache.org" <modperl@apache.org> From: Rasoul Hajikhani <rasoul@rhythm.com> Subject: Apache children Date: Tue, 15 Jan 2002 09:57:53 -0800 Folks, PerlModule directive is supposed to load a module on start up of the server which then the code is shared across requests. However, I have noticed a strange behavior under SGI Irix: Apparently the Apache children each have a copy of the modules and as such global variables are not shared. Now, either I misunderstood the documentation, or indeed this is not the standard behavior. Now to the question part: I have declared My::History as the PerlInitHandler in my httpsd.conf which keeps a history of the requests to the Apache server. In this module there is a global array that is updated with the uri() and args() variables of the request object and returns OK. The array is global and should be accessible from other modules. However, each Apache child loads a copy of this module for itself and therefore defeats the purpose of the history array. notes(), pnotes() are of no use here since they are cleared at the end of the request. Short of sounding completely ignorant and way offish, what is work around? Also, is the above behavior normal? === To: Rasoul Hajikhani <rasoul@rhythm.com> From: Geoffrey Young <geoff@modperlcookbook.org> Subject: Re: Apache children Date: Tue, 15 Jan 2002 14:12:40 -0500 Rasoul Hajikhani wrote: > > Folks, > PerlModule directive is supposed to load a module on start up of the > server which then the code is shared across requests. However, I have > noticed a strange behavior under SGI Irix: > Apparently the Apache children each have a copy of the modules and as > such global variables are not shared. Now, either I misunderstood the > documentation, or indeed this is not the standard behavior. have you read the guide: http://perl.apache.org/guide? :) what you need to understand is apache's pre-fork architecture: each apache process has its own persistent perl interpreter. you can share global variables on a per-apache process basis. the problem with this is that the web is stateless, so over the course of several requests you are not guaranteed to hit the same perl interpreter you had last time (with your data in the global variable). once you get this, you're on the road to enlightenment :) try reading http://perl.apache.org/guide/porting.html to assist in getting things to click in your mind. > Now to the question part: > I have declared My::History as the PerlInitHandler in my httpsd.conf > which keeps a history of the requests to the Apache server. In this > module there is a global array that is updated with the uri() and args() > variables of the request object and returns OK. that seems like an odd thing to be doing, but ok... > The array is global and > should be accessible from other modules. yes, but only in the same perl interpreter. you have multiple interpreters interfacing with the various simultaneous requests you application is processing. > However, each Apache child > loads a copy of this module for itself and therefore defeats the purpose > of the history array. notes(), pnotes() are of no use here since they > are cleared at the end of the request. Short of sounding completely > ignorant and way offish, what is work around? what you are trying to accomplish is state maintainence. Apache::Session is the most common solution, I think. it allows you to share data across the different child processes. there are other solutions as well, but I think that is the most popular. > Also, is the above > behavior normal? yes === To: "Rasoul Hajikhani" <rasoul@rhythm.com>, <modperl@apache.org> From: "Tim Tompkins" <timt@arttoday.com> Subject: Re: Apache children Date: Tue, 15 Jan 2002 12:21:50 -0700 Generally, when a process fork()s off a child, the child is a duplicate of the parent -- inheriting all but the PID, PPID and file locks. This is true for every child that is spawned. However, modifying data within one of the children's processes does not affect the respective data within the sibling processes. So while apache children may receive a copy of the parent's global data when they are spawned, they do not share that data afterwards. This is normal behavior that you're seeing. You could try solutions such as IPC::Shareable, or database storage to allow child processes to share or syncronize data. Just an observation, though, attempting to store a list of requests in RAM could potentially cripple your system on a high traffic site. ===