in reply to Re: Re: cgi environment using mod_perl
in thread cgi environment using mod_perl

I'll remember that in case I ever have to suffer the long journey of porting anything from mod_perl 1.x to mod_perl 1.9x/2.x. That would certainly be a strange thing to see happen if you're not expecting it. :)

Replies are listed 'Best First'.
Re: Re^2: cgi environment using mod_perl
by perrin (Chancellor) on Jan 21, 2004 at 22:13 UTC
    There's a documented workaround for it if you're using prefork. The problem is that chdir is not safe when using threads.

      I really didn't want to hear that. I haven't experienced any problems with this (yet), but what might I expect to happen? Or am I safe because it's within a BEGIN {} block? I could see it causing problems in the middle of the script, but if it's a one-time switch before anything else happens?

      C:\>Apache -V Server version: Apache/2.0.48 [snip] Architecture: 32-bit Server compiled with.... -D APACHE_MPM_DIR="server/mpm/winnt" [snip] C:\>perl -V Summary of my perl5 (revision 5 version 8 subversion 2) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread [snip] usethreads=undef use5005threads=undef useithreads=define usemultip +licity=def ine [snip] Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL +_IMPLICIT_ CONTEXT PERL_IMPLICIT_SYS [snip] C:\> more c:\apache2\conf\httpd.conf [snip] # WinNT MPM # ThreadsPerChild: constant number of worker threads in the server pro +cess # MaxRequestsPerChild: maximum number of requests a server process se +rves <IfModule mpm_winnt.c> ThreadsPerChild 100 MaxRequestsPerChild 0 </IfModule> [snip] LoadFile "C:/Perl/bin/perl58.dll" LoadModule perl_module modules/mod_perl.so [snip] C:\> more c:\apache2\www\port80\test.pl #!c:/perl/bin/perl -w $|++; BEGIN { chdir "C:/Apache2/www/port80" } use strict; use CGI::Simple; [snip]

        Basically, the issue is that chdir changes the current working directory, but that is global to the process, not to a thread. The result is that if anything else does a chdir, you will no longer be in the directory you thought you were in.

        For the most part, as long as all of your scripts chdir to the same place you should be okay. You can probably assume that Apache 2 and mod_perl 2 will not do any chdir stuff, but other CPAN modules might. Best to test with high currency and see what happens, as well as grep'ing any modules you use for chdir.