required files not in a namespace?
Are required files in a namespace under Apache::Registry in Mod_Perl? I have just done a simple test that seems to show that they are not in a namespace. In the documentation (http://perl.apache.org/docs/1.0/guide/intro.html#Apache__Registry) it says that the initial script is stored under a unique key to prevent script name collisions. This seems to work for the main script that you call but not for the required files that that script uses. Here is my example: Test1 Directory test1.pl libone.pl Test2 Directory test1.pl libone.pl test1.pl contains: print Content-type: text/html\n\n; print html; print head; print titleDebug Test #1/title; print /head; print body; require libone.pl; libone::A(); print h1Debug Test #1 Successful/h1; print /body\n/html\n; libone.pl contains: #!/usr/bin/perl package libone; sub A { print Hello from A; } return 1; In the 2nd copy of libone.pl, contained under the Test2 directory I changed the output slightly to say Hello from A - 2nd version. I then restart Apache and try test1.pl from the Test1 directory and I see Hello from A. I then try the test1.pl from the Test2 directory and I still get Hello from A. If I restart Apache and try test1.pl from the Test2 directory first I see Hello from A - 2nd version. If I then try test1.pl from the Test1 directory I still get Hello from A - 2nd version. So it appears as though Apache::Registry is caching the first instance of libone.pl and is not namespacing it as it does with the initial script test1.pl. If this is the case what can I do to fix it? I view it as a big problem because if my script is deployed I do not know if my script is going to use my libone.pl or a libone.pl written by someone else that has already been stored in the cache. I hope you understand my problem. Please help. Thanks. My installation information is below. MOD_PERL = mod_perl/1.26 SERVER_SOFTWARE = Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_python/2.7.6 Python/1.5.2 mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.2 PHP/4.1.2 mod_perl/1.26 mod_throttle/3.1.2 PERL_SEND_HEADER = On
RE: do as temp solution for require problem ?
When a Perl script runs under Mod_Perl the current working directory is no longer the location of the Perl script (I think it is where Apache.exe is). So when you require an additional file it does not look in the same directory as your original script for the file. One alternative that has been mentioned is to place your included file in one of the locations of the @INC array. Another option that I have used is to add the path of the original Perl file to the @INC array so that included files will be looked for there too. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 28, 2003 11:51 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: do as temp solution for require problem ? Hi, Yes, I am using Apache::Registry; how did you know that? ;-) In fact I am trying to change the CGI-Perl pages of http://www.deweertsport.be to mod_perl. As I was used to work with include files in PHP, I sort continued this way of making pages in Perl-CGI. If you look at the previous mentioned site, you can see there is only one file, but it contains a lot of includes. - a random function for the banners on top - a file for the navigation on the left which includes a file for the date and a file for the counter (mysql database) - the content pages with different files for the forms redirected per OS and type of Browser. The reason why I work that way is to have a sort of frame in which the content is included, directed via the variables of the URL. That gives me a good overview on how the site is built and it makes it easy to maintain. Now, with mod_per this is a whole different story. Probably I need to review my strategy as things get more complicated regarding using use, or require ... or do Would using Apache::PerlRun be a better option to deal with this way of building a website? Thanks for your advise! Bart On Tuesday, January 28, 2003, at 05:21 PM, Randal L. Schwartz wrote: mail@adventureforum == mail@adventureforum net [EMAIL PROTECTED] writes: mail@adventureforum I am using: mod_perl/1.26 mail@adventureforum Now I tried to include subroutines from an external .pl file with mail@adventureforum require. This smells a bit like you're using Apache::Registry (you haven't said yet) and you've moved some subroutines into a separate file, but not a separate package, and you either aren't aware or don't understand the significance of the fact that every Apache::Registry script runs in a different package. Could that be the case? If you're using Apache::Registry, and you're not properly using packages, you'll get burned. Turn your external code into a real module, and things will work again. Use use, not require, not do. print Just another (mod) Perl hacker, -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Resetting cache Apache::Registry
I know that when you require or use helper files in a Perl Script, and you are using Apache::Registry, when changes are made to the helper files they are not recognized until you restart Apache. In the documentation it says that you can change the Apache configuration file to do this for you. What I want to know is if there is a way to clear out the files or code in the Apache::Registry cache via a Perl Script. I would like to write a simple Perl Script (clear.pl) that would have some code like $r-ResetCache that would clear out the cache and allow my other Perl script to see the new changes in its helper files. The situation is that Im using a shared server from a 3rd party hosting provider and I do not have control over what they have in their Apache configuration file. Every time I make a change to a helper file I need them to restart Apache. Are there any ideas out there in the world of Mod_Perl gurus? Thank you.
RE: Resetting cache Apache::Registry
Thank you. That is a good suggestion. -Original Message- From: Geoffrey Young [mailto:[EMAIL PROTECTED]] Sent: Tuesday, December 03, 2002 9:56 AM To: Justin Luster Cc: [EMAIL PROTECTED] Subject: Re: Resetting cache Apache::Registry The situation is that I?m using a shared server from a 3rd party hosting provider and I do not have control over what they have in their Apache configuration file. Every time I make a change to a helper file I need them to restart Apache. on the Cobalt and Ensim systems I have websites at, I was able to just create a .htaccess file with PerlInitHandler Apache::StatINC in it and let that take care of everything. HTH --Geoff
RE: Using Perl END{} with Apache::Registry
After doing some additional testing it appears that this problem only occurs on my Windows machine with Apache 2.0. I tried it on my Linux box Apache 1.3 and things worked fine. Since I am not using Windows in a production environment I will be OK. Thanks anyway. -Original Message- From: Jim Schueler [mailto:jschueler;tqis.com] Sent: Tuesday, November 12, 2002 9:02 PM To: Justin Luster Subject: RE: Using Perl END{} with Apache::Registry Pity that the module doesn't help. I spent many hours testing END {} block behavior in Apache::Registry and relied heavily on logged error messages. I cannot confirm your hypothesis that END {} blocks affect error reporting. When testing code, reliable failures are important. If it won't fail predictably, it won't run predictably. I recommend you double check your assumption that It seems to be working fine. Apache::Registry is tricky because it's there's so much uncertainty about the state of a process. For example, it's impossible to determine which sequence various scripts will run in. One of the reasons I recommend my Apache::ChildExit module is because otherwise, all of a process's encountered END {} blocks are run at the end of a request, including END {} blocks from other scripts and all modules that have been imported over the lifetime of the process. Apache::ChildExit eliminates the possibility that unexpected or unknown END {} blocks will impact the process state because it ensures that END {} blocks are only run when the process terminates. -Jim On Tue, 12 Nov 2002, Justin Luster wrote: Thanks for the reply. Unfortunately I need the END block to run for every request. I just was wondering why it altered the way error messages were logged. Thanks. -Original Message- From: Jim Schueler [mailto:jschueler;tqis.com] Sent: Tuesday, November 12, 2002 2:41 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Using Perl END{} with Apache::Registry Hello Justin. I've done a little work on a similar problem due to Apache::Registry's unusual treatment of END {} blocks. You may want to take a look at the module I recently submitted: http://www.cpan.org/authors/id/T/TQ/TQISJIM/ChildExit_0-1.tar.gz -Jim Hi, I'm trying to use the END{ } block in my Perl Scripts to do some code clean up (making sure files are not locked) at the end of each request. It seems to be working fine. I'm using Apache::Registry to run a regular Perl script. I'm having a problem with error messages. I have an included file that I'm requiring: require test.pl; Without the END { } block if the script cannot find test.pl I get a Server error 500 and an appropriate error message in the log file. When I include the END{ } block I get no Server Error and no message in the log file. It is almost as if the END{ } is overwriting the ModPerlRegistry error system. Any ideas? Thanks.
Using Perl END{} with Apache::Registry
Hi, Im trying to use the END{ } block in my Perl Scripts to do some code clean up (making sure files are not locked) at the end of each request. It seems to be working fine. Im using Apache::Registry to run a regular Perl script. Im having a problem with error messages. I have an included file that Im requiring: require test.pl; Without the END { } block if the script cannot find test.pl I get a Server error 500 and an appropriate error message in the log file. When I include the END{ } block I get no Server Error and no message in the log file. It is almost as if the END{ } is overwriting the ModPerlRegistry error system. Any ideas? Thanks.
RE: Using Perl END{} with Apache::Registry
Thanks for the reply. Unfortunately I need the END block to run for every request. I just was wondering why it altered the way error messages were logged. Thanks. -Original Message- From: Jim Schueler [mailto:jschueler;tqis.com] Sent: Tuesday, November 12, 2002 2:41 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Using Perl END{} with Apache::Registry Hello Justin. I've done a little work on a similar problem due to Apache::Registry's unusual treatment of END {} blocks. You may want to take a look at the module I recently submitted: http://www.cpan.org/authors/id/T/TQ/TQISJIM/ChildExit_0-1.tar.gz -Jim Hi, I'm trying to use the END{ } block in my Perl Scripts to do some code clean up (making sure files are not locked) at the end of each request. It seems to be working fine. I'm using Apache::Registry to run a regular Perl script. I'm having a problem with error messages. I have an included file that I'm requiring: require test.pl; Without the END { } block if the script cannot find test.pl I get a Server error 500 and an appropriate error message in the log file. When I include the END{ } block I get no Server Error and no message in the log file. It is almost as if the END{ } is overwriting the ModPerlRegistry error system. Any ideas? Thanks.
RE: Using Perl END{} with Apache::Registry
No. If there is an END block empty or not then the error logging does not happen. By the way do you know of any way to capture what would have been logged and print it through Apache-something? Thanks. -Original Message- From: Perrin Harkins [mailto:perrin;elem.com] Sent: Tuesday, November 12, 2002 3:34 PM To: Justin Luster Cc: [EMAIL PROTECTED] Subject: Re: Using Perl END{} with Apache::Registry Justin Luster wrote: I have an included file that I'm requiring: require test.pl; Without the END { } block if the script cannot find test.pl I get a Server error 500 and an appropriate error message in the log file. When I include the END{ } block I get no Server Error and no message in the log file. It is almost as if the END{ } is overwriting the ModPerlRegistry error system. Does it make any difference if you change what's in the END block? - Perrin
Graphics and mod_perl
Im new to mod_perl and Im really enjoying it. It has really improved performance. Right now Im just using Modperl::Registry to speed up things. I have a question about showing graphics using a Perl Script and running it through mod_perl. Using Perl under regular CGI to create a dynamic web page I have always used: print img src="\thefile.jpg\; and this would display the graphic to the web page assuming that the file thefile.jpg was in the same directory as the Perl script . If the graphic was in another directory then something like: print img src="\../graphics/thefile.jpg\; was used. Now that Im using mod_perl and an Alias to my cgi-bin Im having difficulties knowing how to reference the graphics file. The following directive is in my httpd.conf file. Alias /ssiweb/ C:/Server/htdocs/develop/cgi-bin/ Location /ssiweb SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI PerlOptions +ParseHeaders /Location It seems that the current working directory for the Perl scripts when run under mod_perl is in the bin directory where Apache.exe is. I have considered using absolute paths but even that does not seem to work correctly with graphics. I could also do something like: print img src="\http://www.mysite.com/graphics/thefile.jpg\; but it seems that there is a delay in displaying the graphic when I do this. Where is the current working directory when running a Perl script under mod_perl. I would appreciate any help. Thanks.
Filehandles
I'm using mod_perl 2.0 and Apache::Registry on a Windows XP machine. I'm using a load tester to test my Perl CGI program. I'm reading and writing to files and I'm using flock to control collisions. I keep getting an error when the load tester is going (5 concurrent users). It seems that the file handles are getting messed up. The script will write to files that I never write to but only read. Does anyone know anything about flock and mod_perl? Have you ever seen file handles get messed up where things are being written to the wrong file? Thanks.
Re: Filehandles
Thanks for responding so quickly. flock does work under Windows 2000 and above. The load tester that I'm using works fine with my script outside of mod_perl. My script works inside of mod_perl with only one concurrent user. When multiple concurrent users began hitting the script under mod_perl, using Apache::Registry or Apache::RunPerl all heck breaks loose. It seems that the file locking breaks down. Another thing that is totally bizarre is that stuff is being written to all kinds of files that I'm not writing to. Even my scripts themselves will sometimes have text appended to the end of them. Another problem is that Apache will give me an error message saying that it is trying to write to memory that is locked. Do you have any idea where I can go from here? What it the address of the Win32 mod_perl mailing list? Thanks. - Original Message - From: Perrin Harkins [EMAIL PROTECTED] To: Justin Luster [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, August 29, 2002 12:11 PM Subject: Re: Filehandles Justin Luster wrote: Does anyone know anything about flock and mod_perl? Yes. There is no problem with flock and mod_perl. However, if you were to open a filehandle in startup.pl and then use that same filehandle after forking, that could be a problem. Personally I would suspect Windows in this case. I don't know about XP, but Windows 95/98/ME did not have a working flock. If XP is based on the NT code, it may not have that problem. Even so, I would try testing that first, or maybe asking about it on Win32 perl mailing list. - Perrin
Re: Filehandles
The stress tool that I'm using is from Microsoft and is a free download. It is called Web Application Stress. There is a setting in this tool called Concurrent Connections (threads). As I mentioned before I am able to do this no problem under regular CGI with 10 concurrent users but when I run mod_perl all heck breaks loose. - Original Message - From: Perrin Harkins [EMAIL PROTECTED] To: Justin Luster [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, August 29, 2002 1:44 PM Subject: Re: Filehandles Justin Luster wrote: The load tester that I'm using works fine with my script outside of mod_perl. Does it work when running them concurrently under CGI? When multiple concurrent users began hitting the script under mod_perl, using Apache::Registry or Apache::RunPerl all heck breaks loose. Hmmm, which version of mod_perl are you using? If you're using 2.x, I can't help you there since I've never tried it on Win32. Maybe Randy will have some ideas. If you have 1.x, there is no concurreny under mod_perl -- requests are serialized. - Perrin