SlideShare a Scribd company logo
1 of 84
Download to read offline
From CGI to mod_perl 2.0, Fast!




                                                                Philippe M. Chiasson
                                                           gozer@ectoplasm.org




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Fast!
$> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz
$> tar zxvf mod_perl-2.0-current.tar.gz
[...]
$> cd mod_perl-2.0.*/
$> perl Makefile.PL MP_APXS=`which apxs`
Configuring Apache/2.0.52 mod_perl2/2.0.2 Perl/v5.8.6
[...]
$> make
cd quot;src/modules/perlquot; && make
[...]
$> make test

$> make install
$> perl -pi -e’s/cgi_module/perl_module/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> perl -pi -e’s/mod_cgi/mod_perl/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> perl -pi -e’s/cgi-script/perl-script/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> `apxs -q SBINDIR`/apachectl configtest
Syntax OK
$> `apxs -q SBINDIR`/apachectl restart



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Faster!


 $> wget -O-       http://gozer.ectoplasm.org/talks/ApacheCon/2005/US/mod_perl-2.0-cgi-fast/fast.sh   | sh -x




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Better!

 $> yum install mod_perl

 $> apt-get mod_perl

 $> fink install mod_perl

 $> pkg_add -r mod_perl

 $> emerge mod_perl




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Thank You!




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Do we still have time?


                                    Let’s get serious!




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
You have

     • Apache 2.x
     • mod_cgi
     • A bunch of Perl CGI scripts
     • A working web site
     • A good job

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Common Gateway
                 Interface

     • CGI is simple
     • CGI is easy
     • CGI just works


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How about mod_perl?


     • mod_perl is simple
     • mod_perl is easy
     • mod_perl just works


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How about mod_perl?


     • mod_perl is simple
     • mod_perl is easy
     • mod_perl just works BETTER


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How about mod_perl?


     • mod_perl is simple
     • mod_perl is easy
     • mod_perl just works FASTER


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How about mod_perl?


     • mod_perl is simple
     • mod_perl is easy
     • mod_perl just works EASIERer


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
But why switch?

     • CPU cycles
     • Memory
     • Servers
     • $$$
     • Apache::* module on CPAN

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
The CGI model


     • Forking
     • Startup
     • Teardown


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
The CGI model
     •    httpd fork()s

     •    httpd exec(/var/www/cgi-bin/myscript.pl)

     •    OS find #!/usr/bin/perl in /var/www/cgi-bin/myscript.pl

     •    OS fork()s

     •    OS exec()s /usr/bin/perl

     •    Perl opens, initializes and parses myscript.pl

     •    Perl runs the script


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
The CGI model

                                            2x fork()
                                            2x exec()
                                           Perl startup
                                          Perl shutdown



                    EXPENSIVE
Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
The mod_perl model


     • Embedded Perl
     • One time startup
     • One time teardown


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
The mod_perl model


     •    Perl locates the correct subroutine to invoke

     •    Perl calls it




                            CHEAP                          er




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Getting there from here




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_cgi setup

 LoadModule cgi_module libexec/mod_cgi.so

 ScriptAlias /cgi-bin/ /var/www/cgi-bin




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_cgi setup
                        ScriptAlias is just shorthand
  LoadModule cgi_module libexec/mod_cgi.so

  Alias /cgi-bin /var/www/cgi-bin
  <Location /cgi-bin>
    SetHandler cgi-script
    Option +ExecCGI
  </Location>




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_cgi setup
 /var/www/cgi-bin/hello.pl
  #!/usr/bin/perl

  use CGI;

  my $q = new CGI;

  print $q->header('text/html');

  print <<quot;EOFquot;;
  <html><body>
  <h1>Hello world!</h1>
  <pre>
  GATEWAY_INTERFACE: $ENV{GATEWAY_INTERFACE}
  MOD_PERL: $ENV{MOD_PERL}
  </pre>
  </body></html>
  EOF


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_cgi setup




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is that ?

     • Apache Bench (ab)
     • Nice benchmarking tool
     • Will work for us nicely
     • Comes with Apache

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is that ?

  $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    5.57 [#/sec] (mean)
  Time per request:       179.448 [ms] (mean)
  Transfer rate:          1.67 [Kbytes/sec] received




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time
$> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz
$> tar zxvf mod_perl-2.0-current.tar.gz
[...]
$> cd mod_perl-2.0.*/
$> perl Makefile.PL MP_APXS=`which apxs`
Configuring Apache/2.0.52 mod_perl2/2.0.x Perl/v5.8.6
[...]
$> make
cd quot;src/modules/perlquot; && make
[...]
$> make test

$> make install
$> perl -pi -e’s/cgi_module/perl_module/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> perl -pi -e’s/mod_cgi/mod_perl/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> perl -pi -e’s/cgi-script/perl-script/g’ `apxs -q SYSCONFDIR`/httpd.conf
$> `apxs -q SBINDIR`/apachectl configtest
Syntax OK
$> `apxs -q SBINDIR`/apachectl restart



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time

                                Download & unpack
$> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz
$> tar zxvf mod_perl-2.0-current.tar.gz
[...]
$> cd mod_perl-2.0.*/




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time

                                           Configure

$> /usr/bin/perl Makefile.PL MP_APXS=/usr/sbin/apxs
Configuring Apache/2.0.52 mod_perl2/2.0.x Perl/v5.8.6
[...]




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time

                                    Build, test, install

$> make
$> make test
$> make install




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time

                                  Check your distro!
             mod_perl is supported by lots of them




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time
                                           httpd.conf
  LoadModule cgi_module modules/mod_cgi.so
  LoadModule perl_module modules/mod_perl.so

  Alias /cgi-bin /var/www/cgi-bin
  Alias /perlrun /var/www/cgi-bin

  <Location /cgi-bin>
    SetHandler cgi-script
    Option +ExecCGI
  </Location>
  <Location /perlrun>
    SetHandler perl-script
    Option +ExecCGI
    PerlHandler ModPerl::PerlRun
  </Location>


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time


     • SetHandler
     • PerlHandler
     • ModPerl::PerlRun


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time

  $> apachectl restart
  [notice] Apache/2.0.52 (Unix) mod_perl/2.0.x Perl/v5.8.7 configured




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
mod_perl time




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
it works!


     • $ENV{MOD_PERL} = “mod_perl/2.0.x”;



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?

  $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    83.15 [#/sec] (mean)
  Time per request:       12.027 [ms] (mean)
  Transfer rate:          26.61 [Kbytes/sec] received




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?
  mod_cgi
  $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    5.57 [#/sec] (mean)
  Time per request:       179.448 [ms] (mean)
  Transfer rate:          1.67 [Kbytes/sec] received


  ModPerl::PerlRun
  $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    83.15 [#/sec] (mean)
  Time per request:       12.027 [ms] (mean)
  Transfer rate:          26.61 [Kbytes/sec] received




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?
  mod_cgi
  $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    5.57 [#/sec] (mean)
  Time per request:       179.448 [ms] (mean)
  Transfer rate:          1.67 [Kbytes/sec] received


  ModPerl::PerlRun
  $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    15x(mod_cgi) [#/sec] (mean)
  Time per request:       15x(mod_cgi) [ms] (mean)
  Transfer rate:          16x(mod_cgi) [Kbytes/sec] received




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::PerlRun


     • mod_perl’s bundled module
     • closest CGI emulation available


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::PerlRun
       On every request for the script:
     •    Found

     •    Loaded

     •    Parsed

     •    BEGIN {}

     •    Executed

     •    END {}

     •    Destroyed


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::Registry
                                           httpd.conf
 Alias /cgi-bin /var/www/cgi-bin
 Alias /perlrun /var/www/cgi-bin
 Alias /registry /var/www/cgi-bin

 <Location /cgi-bin>
   SetHandler cgi-script
   Option +ExecCGI
 </Location>
 <Location /perlrun>
   SetHandler perl-script
   Option +ExecCGI
   PerlHandler ModPerl::PerlRun
 </Location>
 <Location /perlrun>
   SetHandler perl-script
   Option +ExecCGI
   PerlHandler ModPerl::Registry
 </Location>



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::Registry




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?

  $> ab -c1 -n50 http://localhost:8529/registry/hello.pl
  Benchmarking 127.0.0.1 (be patient).....done
  Requests per second:    156.37 [#/sec] (mean)
  Time per request:       6.395 [ms] (mean)
  Transfer rate:          50.04 [Kbytes/sec] received




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?
 mod_cgi
 $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl
 Benchmarking 127.0.0.1 (be patient).....done
 Requests per second:    5.57 [#/sec] (mean)
 Time per request:       179.448 [ms] (mean)
 Transfer rate:          1.67 [Kbytes/sec] received


 ModPerl::PerlRun
 $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl
 Benchmarking 127.0.0.1 (be patient).....done
 Requests per second:    83.15 [#/sec] (mean)
 Time per request:       12.027 [ms] (mean)
 Transfer rate:          26.61 [Kbytes/sec] received

 ModPerl::Registry
$> ab -c1 -n50 http://localhost:8529/registry/hello.pl
Benchmarking 127.0.0.1 (be patient).....done
Requests per second:    156.37 [#/sec] (mean)
Time per request:       6.395 [ms] (mean)
Transfer rate:          50.04 [Kbytes/sec] received

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
How fast is THAT ?
 mod_cgi
 $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl
 Benchmarking 127.0.0.1 (be patient).....done
 Requests per second:    5.57 [#/sec] (mean)
 Time per request:       179.448 [ms] (mean)
 Transfer rate:          1.67 [Kbytes/sec] received

 ModPerl::PerlRun
 $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl
 Benchmarking 127.0.0.1 (be patient).....done
 Requests per second:    15x(mod_cgi) [#/sec] (mean)
 Time per request:       15x(mod_cgi) [ms] (mean)
 Transfer rate:          16x(mod_cgi) [Kbytes/sec] received

 ModPerl::Registry
$> ab -c1 -n50 http://localhost:8529/registry/hello.pl
Benchmarking 127.0.0.1 (be patient).....done
Requests per second:    28x(mod_cgi) [#/sec] (mean)
Time per request:       28x(mod_cgi) [ms] (mean)
Transfer rate:          30x(mod_cgi) [Kbytes/sec] received

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::Registry


     • mod_perl’s bundled module
     • Faster, but CGI emulation laking


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::Registry
       On every request for the script:
     •    Load from file if:

          •   Not found in cache

          •   Cache entry is older than the file

     •    BEGIN {}

     •    Executed

     •    END {}




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::(PerlRun|Registry)

     • Try ModPerl::Registry first
      • faster
      • might break some CGIs
     • Try ModPerl::PerlRun after
      • slower
      • might break CGIs                  some




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
ModPerl::(PerlRun|Registry)


     • Simple Perl modules
     • Designed to run perl scripts from mod_perl
           pretending it’s a CGI
     • Derives from ModPerl::RegistryCooker
     • New ones can be made in a pinch

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
package ModPerl::PerlRun;
             use base qw(ModPerl::RegistryCooker);

             sub handler : method {
                 my $class = (@_ >= 2) ? shift : __PACKAGE__;
                 my $r = shift;
                 return $class->new($r)->default_handler();
             }

             my $parent = 'ModPerl::RegistryCooker';
             my %aliases = (
                 new             => 'new',
                 init            => 'init',
                 default_handler => 'default_handler',
                 run             => 'run',
                 can_compile     => 'can_compile',
                 make_namespace => 'make_namespace',
                 namespace_root => 'namespace_root',
                 namespace_from => 'namespace_from_filename',
                 is_cached       => 'FALSE',
                 should_compile => 'TRUE',
                 flush_namespace => 'flush_namespace_normal',
                 cache_table     => 'cache_table_common',
                 cache_it        => 'NOP',
                 read_script     => 'read_script',
                 shebang_to_perl => 'shebang_to_perl',
                 get_script_name => 'get_script_name',
                 chdir_file      => 'NOP',
                 get_mark_line   => 'get_mark_line',
                 compile         => 'compile',
                 error_check     => 'error_check',
                 should_reset_inc_hash => 'TRUE',
                 strip_end_data_segment              => 'strip_end_data_segment',
                 convert_script_to_compiled_handler =>
             'convert_script_to_compiled_handler',
             );

             $aliases{$_} = $parent . quot;::quot; . $aliases{$_} for keys %aliases;
             __PACKAGE__->install_aliases(%aliases);

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
CGI emulation


     • It’s an emulation
     • It ain’t the real thing
     • things can go wonky


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I remember
   #!/usr/bin/perl

   use CGI;

   my $q = new CGI;

   print $q->header('text/plain');

   $counter++;

   print <<quot;EOFquot;;
   counted $counter
   EOF




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
#!/usr/bin/perl
                             I remember
  use CGI;

  my $q = new CGI;

  print $q->header('text/plain');

  $counter++;

  print <<quot;EOFquot;;
  counted $counter
  EOF
                        $> GET http://localhost:8529/cgi-bin/count.pl
                        counted 1
                        $> GET http://localhost:8529/cgi-bin/count.pl
                        counted 1
                        $> GET http://localhost:8529/cgi-bin/count.pl
                        counted 1




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
#!/usr/bin/perl
                             I remember
  use CGI;

  my $q = new CGI;

  print $q->header('text/plain');

  $counter++;

  print <<quot;EOFquot;;
  counted $counter
  EOF                              $> GET http://localhost:8529/registry/count.pl
                                   counted 1
                                   $> GET http://localhost:8529/registry/count.pl
                                   counted 2
                                   $> GET http://localhost:8529registry/count.pl
                                   counted 3
                                   $> GET http://localhost:8529registry/count.pl
                                   counted 1
                                   $> GET http://localhost:8529registry/count.pl
                                   counted 4


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
That can’t be right?
   #!/usr/bin/perl

   use CGI;

   my $q = new CGI;

   print $q->header('text/plain');

   $counter++;

   print <<quot;EOFquot;;
   counted $counter
   EOF




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
That can’t be right?

     • Code is cached
     • Perl sticks around
     • Great for speed
     • Globals are suddently VERY GLOBAL

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
That can’t be right?
   #!/usr/bin/perl

   use CGI;

   my $q = new CGI;

   print $q->header('text/plain');

   $counter++;

   print <<quot;EOFquot;;
   counted $counter
   EOF




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
That can’t be right?
   #!/usr/bin/perl

   use CGI;

   my $q = new CGI;

   print $q->header('text/plain');

   $main::counter++;              # GLOBAL!

   print <<quot;EOFquot;;
   counted $counter
   EOF




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
That can be right!
   #!/usr/bin/perl

   use CGI;

   my $counter;
   my $q = new CGI;

   print $q->header('text/plain');

   $counter++;

   print <<quot;EOFquot;;
   counted $counter
   EOF




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Globals will stick


     • Globals will stick around
     • Use my
     •   Try ModPerl::PerlRun




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
CGI emulation


     • It’s an emulation
     • It ain’t the real thing
     • things can go wonky


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I still remember
  #!/usr/bin/perl
                                                           $> GET http://localhost:8529/registry/count.pl
                                                           Counter: 1
  use CGI;
                                                           $> GET http://localhost:8529/registry/count.pl
  use strict;
  use warnings;                                            Counter: 2
                                                           $> GET http://localhost:8529/registry/count.pl
  my $q = new CGI;                                         Counter: 3
  my $counter;                                             $> GET http://localhost:8529/registry/count.pl
                                                           Counter: 1
  print $q->header('text/plain');                          $> GET http://localhost:8529/registry/count.pl
                                                           Counter: 4
  counter_up();

  sub counter_up {
  
   $counter++;
  
   print quot;Counter: $counternquot;;
  }




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
But, what the..?

     • I used my so it’s not a global...
     • To Perl, all code lives in subroutines
     • mod_perl turns scripts into subroutines
     • subroutines can create closures

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
subification       *




                                   #!/usr/bin/perl

                                   use CGI;
                                   use strict;
                                   use warnings;

                                   my $q = new CGI;
                                   my $counter;

                                   print $q->header('text/plain');

                                   counter_up();

                                   sub counter_up {
                                   
   $counter++;
                                   
   print quot;Counter: $counternquot;;
                                   }


  * the process of making a subroutine, obviously



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
subification   *




       • subroutine needs a name
       • filepath is a convenient naming

  * the process of making a subroutine, obviously



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
subification         *




                                                /var/www/cgi-bin/hello.pl

         ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_hello_2epl::handler



                                         Prefix                        Path   Sub




  * the process of making a subroutine, obviously



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
sub
                              subification                  *




ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_count_2epl::handler {
package ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_count_2epl;
no warnings;
local $0 = '/var/www/cgi-bin/count.pl’;

use CGI;
use strict;
use warnings;

my $q = new CGI;
my $counter;

print $q->header('text/plain');

counter_up();

sub counter_up {

      $counter++;

      print quot;Counter: $counternquot;;
}
} the process of making a subroutine, obviously
  *



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
closures
     • Closures are a Perl feature
     • Come to be when creating subs
     • Normally not an issue
     • mod_perl can create some without telling
           you
     • man perlref for more
Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I still remember
  #!/usr/bin/perl

  use CGI;                                             2 warning signs to look for:
  use strict;
  use warnings;
                                                                 globals
  my $q = new CGI;
  my $counter;                                                 error_log:
  print $q->header('text/plain');                    Variable quot;$counterquot; will not stay
                                                        shared at /var/www/cgi-bin/
  counter_up();                                                   count.pl
  sub counter_up {
  
   $counter++;    # GLOBAL
  
   print quot;Counter: $counternquot;;
  }




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I still remember
  #!/usr/bin/perl

  use CGI;
  use strict;
  use warnings;
                                                             Just remember that
                                                           globals in general are to
  my $q = new CGI;
  my $counter;

  print $q->header('text/plain');                               watch out for
  counter_up($counter);

  sub   counter_up {
  
     my $counter = shift;
  
     $counter++;    # GLOBAL
  
     print quot;Counter: $counternquot;;
  }




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Good advice

     • use strict;
     • use warnings;
     • avoid globals
     • look for hints in your error_log file

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
CGI emulation


     • It’s an emulation
     • It ain’t the real thing
     • things can go wonky


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I used to work
  #!/usr/bin/perl                                          #countlib.pl

  use CGI;                                                 use strict;
  use strict;                                              my $counter = 0;
  use warnings;
                                                           sub counter_up {
  require quot;countlib.plquot;;                                   
   $counter++;
                                                           
   print “Counter: $countern”;
  my $q = new CGI;                                         }

  print $q->header('text/plain');

  counter_up();




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I used to work




 error_log:
  [Sun Oct 23 21:37:44 2005] [error] Can't locate countlib.pl in @INC (@INC
  contains: [...]) at /var/www/cgi-bin/hello.pl line 7.n


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I used to work
  #!/usr/bin/perl

  use   CGI;
  use   strict;
  use   warnings;
  use   Cwd;

  my $q = new CGI;

  print $q->header('text/plain');
  print “Cwd: “, cwd(), “n”;



              $> GET http://localhost:8529/cgi-bin/cwd.pl
              Cwd: /var/www/cgi-bin
              $> GET http://localhost:8529/registry/cwd.pl
              Cwd: /




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
I used to work


     • mod_cgi
      • fork()s
      • chdir()s to the script’s directory


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Cwd

     • mod_perl
      • doesn’t fork()
      • doesn’t chdir()s
      • could chdir()s

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Cwd

     • Cwd() is a process proprety
     • Apache threaded MPMs
     • chdir() isn’t thread-safe
     • mod_perl doesn’t try to break things

Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Cwd


     • You can fix your scripts
      • use lib();
      • require “/fully/qualfied/lib/path.pl”;


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Cwd


     • If your MPM is Prefork:
      • ModPerl::RegistryPrefork
      • ModPerl::PerlRunPrefork


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
It ain’t magical!


     • use strict/warnings
     • Think about globals
     • watch the error_log


Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
More info
     • mod_perl User’s mailing-list
          – http://perl.apache.org/maillist/modperl.html
          – <modperl@perl.apache.org>

     • mod_perl Developer's Cookbook
          – http://www.modperlcookbook.org/

     • – http://www.modperlbook.org/
       Practical mod_perl

     • – http://perl.apache.org/
       mod_perl at the ASF



Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
Thank You!

                          Slides and bonus material:

                     http://gozer.ectoplasm.org/talk/




Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/

More Related Content

What's hot

Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册
Yiwei Ma
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Install apache on centos
Install apache on centosInstall apache on centos
Install apache on centos
hengko
 

What's hot (20)

Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)
 
Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册Nginx 0.9.x 安装手册
Nginx 0.9.x 安装手册
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Py conkr 20150829_docker-python
Py conkr 20150829_docker-pythonPy conkr 20150829_docker-python
Py conkr 20150829_docker-python
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
 
Docker remote-api
Docker remote-apiDocker remote-api
Docker remote-api
 
Http capturing
Http capturingHttp capturing
Http capturing
 
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous TestingGuarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
 
はじめてのSymfony2
はじめてのSymfony2はじめてのSymfony2
はじめてのSymfony2
 
Continuous testing In PHP
Continuous testing In PHPContinuous testing In PHP
Continuous testing In PHP
 
Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
 
Perlmania_Study - CPAN
Perlmania_Study - CPANPerlmania_Study - CPAN
Perlmania_Study - CPAN
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Running PHP on nginx
Running PHP on nginxRunning PHP on nginx
Running PHP on nginx
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Install apache on centos
Install apache on centosInstall apache on centos
Install apache on centos
 
Fun with Ruby and Cocoa
Fun with Ruby and CocoaFun with Ruby and Cocoa
Fun with Ruby and Cocoa
 

Viewers also liked

『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
Masahiro Nagano
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
Dave Cross
 
Carton CPAN dependency manager
Carton CPAN dependency managerCarton CPAN dependency manager
Carton CPAN dependency manager
Tatsuhiko Miyagawa
 

Viewers also liked (18)

Shopper Insights
Shopper InsightsShopper Insights
Shopper Insights
 
Turning shopper insights into company-wide memes: Danone disrupts shopper res...
Turning shopper insights into company-wide memes: Danone disrupts shopper res...Turning shopper insights into company-wide memes: Danone disrupts shopper res...
Turning shopper insights into company-wide memes: Danone disrupts shopper res...
 
Shopper Insights
Shopper InsightsShopper Insights
Shopper Insights
 
Hachiojipm41
Hachiojipm41Hachiojipm41
Hachiojipm41
 
nginx mod PSGI
nginx mod PSGInginx mod PSGI
nginx mod PSGI
 
Introduction to PSGI
Introduction to PSGIIntroduction to PSGI
Introduction to PSGI
 
Web::Scraper for SF.pm LT
Web::Scraper for SF.pm LTWeb::Scraper for SF.pm LT
Web::Scraper for SF.pm LT
 
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
『How to build a High Performance PSGI/Plack Server』のその後と ISUCON3を受けての話題
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonApache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Maximizing Profits through Shopper Insights in Convenience (CSFA Presentation)
Maximizing Profits through Shopper Insights in Convenience (CSFA Presentation)Maximizing Profits through Shopper Insights in Convenience (CSFA Presentation)
Maximizing Profits through Shopper Insights in Convenience (CSFA Presentation)
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
 
Carton CPAN dependency manager
Carton CPAN dependency managerCarton CPAN dependency manager
Carton CPAN dependency manager
 
Online Grocery Shopper Behaviour
Online Grocery Shopper BehaviourOnline Grocery Shopper Behaviour
Online Grocery Shopper Behaviour
 
Coca Cola
Coca ColaCoca Cola
Coca Cola
 
Venture Design Workshop: Business Model Canvas
Venture Design Workshop: Business Model CanvasVenture Design Workshop: Business Model Canvas
Venture Design Workshop: Business Model Canvas
 

Similar to From CGI to mod_perl 2.0, Fast!

Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
Combell NV
 
Painless Perl Ports with cpan2port
Painless Perl Ports with cpan2portPainless Perl Ports with cpan2port
Painless Perl Ports with cpan2port
Benny Siegert
 
Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧
Orange Tsai
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
Hash Lin
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 

Similar to From CGI to mod_perl 2.0, Fast! (20)

mod_perl 2.0 For Speed Freaks!
mod_perl 2.0 For Speed Freaks!mod_perl 2.0 For Speed Freaks!
mod_perl 2.0 For Speed Freaks!
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Php Power Tools
Php Power ToolsPhp Power Tools
Php Power Tools
 
Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Deploying PHP Applications with Ansible
Deploying PHP Applications with AnsibleDeploying PHP Applications with Ansible
Deploying PHP Applications with Ansible
 
Self revisor
Self revisorSelf revisor
Self revisor
 
Painless Perl Ports with cpan2port
Painless Perl Ports with cpan2portPainless Perl Ports with cpan2port
Painless Perl Ports with cpan2port
 
Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Php through the eyes of a hoster
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hoster
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
 
php & performance
 php & performance php & performance
php & performance
 

Recently uploaded

pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 

From CGI to mod_perl 2.0, Fast!

  • 1. From CGI to mod_perl 2.0, Fast! Philippe M. Chiasson gozer@ectoplasm.org Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 2. Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 3. Fast! $> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz $> tar zxvf mod_perl-2.0-current.tar.gz [...] $> cd mod_perl-2.0.*/ $> perl Makefile.PL MP_APXS=`which apxs` Configuring Apache/2.0.52 mod_perl2/2.0.2 Perl/v5.8.6 [...] $> make cd quot;src/modules/perlquot; && make [...] $> make test $> make install $> perl -pi -e’s/cgi_module/perl_module/g’ `apxs -q SYSCONFDIR`/httpd.conf $> perl -pi -e’s/mod_cgi/mod_perl/g’ `apxs -q SYSCONFDIR`/httpd.conf $> perl -pi -e’s/cgi-script/perl-script/g’ `apxs -q SYSCONFDIR`/httpd.conf $> `apxs -q SBINDIR`/apachectl configtest Syntax OK $> `apxs -q SBINDIR`/apachectl restart Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 4. Faster! $> wget -O- http://gozer.ectoplasm.org/talks/ApacheCon/2005/US/mod_perl-2.0-cgi-fast/fast.sh | sh -x Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 5. Better! $> yum install mod_perl $> apt-get mod_perl $> fink install mod_perl $> pkg_add -r mod_perl $> emerge mod_perl Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 6. Thank You! Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 7. Do we still have time? Let’s get serious! Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 8. You have • Apache 2.x • mod_cgi • A bunch of Perl CGI scripts • A working web site • A good job Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 9. Common Gateway Interface • CGI is simple • CGI is easy • CGI just works Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 10. How about mod_perl? • mod_perl is simple • mod_perl is easy • mod_perl just works Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 11. How about mod_perl? • mod_perl is simple • mod_perl is easy • mod_perl just works BETTER Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 12. How about mod_perl? • mod_perl is simple • mod_perl is easy • mod_perl just works FASTER Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 13. How about mod_perl? • mod_perl is simple • mod_perl is easy • mod_perl just works EASIERer Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 14. But why switch? • CPU cycles • Memory • Servers • $$$ • Apache::* module on CPAN Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 15. The CGI model • Forking • Startup • Teardown Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 16. The CGI model • httpd fork()s • httpd exec(/var/www/cgi-bin/myscript.pl) • OS find #!/usr/bin/perl in /var/www/cgi-bin/myscript.pl • OS fork()s • OS exec()s /usr/bin/perl • Perl opens, initializes and parses myscript.pl • Perl runs the script Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 17. The CGI model 2x fork() 2x exec() Perl startup Perl shutdown EXPENSIVE Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 18. The mod_perl model • Embedded Perl • One time startup • One time teardown Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 19. The mod_perl model • Perl locates the correct subroutine to invoke • Perl calls it CHEAP er Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 20. Getting there from here Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 21. mod_cgi setup LoadModule cgi_module libexec/mod_cgi.so ScriptAlias /cgi-bin/ /var/www/cgi-bin Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 22. mod_cgi setup ScriptAlias is just shorthand LoadModule cgi_module libexec/mod_cgi.so Alias /cgi-bin /var/www/cgi-bin <Location /cgi-bin> SetHandler cgi-script Option +ExecCGI </Location> Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 23. mod_cgi setup /var/www/cgi-bin/hello.pl #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header('text/html'); print <<quot;EOFquot;; <html><body> <h1>Hello world!</h1> <pre> GATEWAY_INTERFACE: $ENV{GATEWAY_INTERFACE} MOD_PERL: $ENV{MOD_PERL} </pre> </body></html> EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 24. mod_cgi setup Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 25. How fast is that ? • Apache Bench (ab) • Nice benchmarking tool • Will work for us nicely • Comes with Apache Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 26. How fast is that ? $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 5.57 [#/sec] (mean) Time per request: 179.448 [ms] (mean) Transfer rate: 1.67 [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 27. mod_perl time $> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz $> tar zxvf mod_perl-2.0-current.tar.gz [...] $> cd mod_perl-2.0.*/ $> perl Makefile.PL MP_APXS=`which apxs` Configuring Apache/2.0.52 mod_perl2/2.0.x Perl/v5.8.6 [...] $> make cd quot;src/modules/perlquot; && make [...] $> make test $> make install $> perl -pi -e’s/cgi_module/perl_module/g’ `apxs -q SYSCONFDIR`/httpd.conf $> perl -pi -e’s/mod_cgi/mod_perl/g’ `apxs -q SYSCONFDIR`/httpd.conf $> perl -pi -e’s/cgi-script/perl-script/g’ `apxs -q SYSCONFDIR`/httpd.conf $> `apxs -q SBINDIR`/apachectl configtest Syntax OK $> `apxs -q SBINDIR`/apachectl restart Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 28. mod_perl time Download & unpack $> wget http://perl.apache.org/download/mod_perl-2.0-current.tar.gz $> tar zxvf mod_perl-2.0-current.tar.gz [...] $> cd mod_perl-2.0.*/ Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 29. mod_perl time Configure $> /usr/bin/perl Makefile.PL MP_APXS=/usr/sbin/apxs Configuring Apache/2.0.52 mod_perl2/2.0.x Perl/v5.8.6 [...] Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 30. mod_perl time Build, test, install $> make $> make test $> make install Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 31. mod_perl time Check your distro! mod_perl is supported by lots of them Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 32. mod_perl time httpd.conf LoadModule cgi_module modules/mod_cgi.so LoadModule perl_module modules/mod_perl.so Alias /cgi-bin /var/www/cgi-bin Alias /perlrun /var/www/cgi-bin <Location /cgi-bin> SetHandler cgi-script Option +ExecCGI </Location> <Location /perlrun> SetHandler perl-script Option +ExecCGI PerlHandler ModPerl::PerlRun </Location> Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 33. mod_perl time • SetHandler • PerlHandler • ModPerl::PerlRun Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 34. mod_perl time $> apachectl restart [notice] Apache/2.0.52 (Unix) mod_perl/2.0.x Perl/v5.8.7 configured Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 35. mod_perl time Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 36. it works! • $ENV{MOD_PERL} = “mod_perl/2.0.x”; Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 37. How fast is THAT ? $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 83.15 [#/sec] (mean) Time per request: 12.027 [ms] (mean) Transfer rate: 26.61 [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 38. How fast is THAT ? mod_cgi $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 5.57 [#/sec] (mean) Time per request: 179.448 [ms] (mean) Transfer rate: 1.67 [Kbytes/sec] received ModPerl::PerlRun $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 83.15 [#/sec] (mean) Time per request: 12.027 [ms] (mean) Transfer rate: 26.61 [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 39. How fast is THAT ? mod_cgi $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 5.57 [#/sec] (mean) Time per request: 179.448 [ms] (mean) Transfer rate: 1.67 [Kbytes/sec] received ModPerl::PerlRun $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 15x(mod_cgi) [#/sec] (mean) Time per request: 15x(mod_cgi) [ms] (mean) Transfer rate: 16x(mod_cgi) [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 40. ModPerl::PerlRun • mod_perl’s bundled module • closest CGI emulation available Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 41. ModPerl::PerlRun On every request for the script: • Found • Loaded • Parsed • BEGIN {} • Executed • END {} • Destroyed Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 42. ModPerl::Registry httpd.conf Alias /cgi-bin /var/www/cgi-bin Alias /perlrun /var/www/cgi-bin Alias /registry /var/www/cgi-bin <Location /cgi-bin> SetHandler cgi-script Option +ExecCGI </Location> <Location /perlrun> SetHandler perl-script Option +ExecCGI PerlHandler ModPerl::PerlRun </Location> <Location /perlrun> SetHandler perl-script Option +ExecCGI PerlHandler ModPerl::Registry </Location> Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 43. ModPerl::Registry Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 44. How fast is THAT ? $> ab -c1 -n50 http://localhost:8529/registry/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 156.37 [#/sec] (mean) Time per request: 6.395 [ms] (mean) Transfer rate: 50.04 [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 45. How fast is THAT ? mod_cgi $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 5.57 [#/sec] (mean) Time per request: 179.448 [ms] (mean) Transfer rate: 1.67 [Kbytes/sec] received ModPerl::PerlRun $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 83.15 [#/sec] (mean) Time per request: 12.027 [ms] (mean) Transfer rate: 26.61 [Kbytes/sec] received ModPerl::Registry $> ab -c1 -n50 http://localhost:8529/registry/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 156.37 [#/sec] (mean) Time per request: 6.395 [ms] (mean) Transfer rate: 50.04 [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 46. How fast is THAT ? mod_cgi $> ab -c1 -n50 http://localhost:8529/cgi-bin/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 5.57 [#/sec] (mean) Time per request: 179.448 [ms] (mean) Transfer rate: 1.67 [Kbytes/sec] received ModPerl::PerlRun $> ab -c1 -n50 http://localhost:8529/perlrun/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 15x(mod_cgi) [#/sec] (mean) Time per request: 15x(mod_cgi) [ms] (mean) Transfer rate: 16x(mod_cgi) [Kbytes/sec] received ModPerl::Registry $> ab -c1 -n50 http://localhost:8529/registry/hello.pl Benchmarking 127.0.0.1 (be patient).....done Requests per second: 28x(mod_cgi) [#/sec] (mean) Time per request: 28x(mod_cgi) [ms] (mean) Transfer rate: 30x(mod_cgi) [Kbytes/sec] received Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 47. ModPerl::Registry • mod_perl’s bundled module • Faster, but CGI emulation laking Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 48. ModPerl::Registry On every request for the script: • Load from file if: • Not found in cache • Cache entry is older than the file • BEGIN {} • Executed • END {} Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 49. ModPerl::(PerlRun|Registry) • Try ModPerl::Registry first • faster • might break some CGIs • Try ModPerl::PerlRun after • slower • might break CGIs some Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 50. ModPerl::(PerlRun|Registry) • Simple Perl modules • Designed to run perl scripts from mod_perl pretending it’s a CGI • Derives from ModPerl::RegistryCooker • New ones can be made in a pinch Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 51. package ModPerl::PerlRun; use base qw(ModPerl::RegistryCooker); sub handler : method { my $class = (@_ >= 2) ? shift : __PACKAGE__; my $r = shift; return $class->new($r)->default_handler(); } my $parent = 'ModPerl::RegistryCooker'; my %aliases = ( new => 'new', init => 'init', default_handler => 'default_handler', run => 'run', can_compile => 'can_compile', make_namespace => 'make_namespace', namespace_root => 'namespace_root', namespace_from => 'namespace_from_filename', is_cached => 'FALSE', should_compile => 'TRUE', flush_namespace => 'flush_namespace_normal', cache_table => 'cache_table_common', cache_it => 'NOP', read_script => 'read_script', shebang_to_perl => 'shebang_to_perl', get_script_name => 'get_script_name', chdir_file => 'NOP', get_mark_line => 'get_mark_line', compile => 'compile', error_check => 'error_check', should_reset_inc_hash => 'TRUE', strip_end_data_segment => 'strip_end_data_segment', convert_script_to_compiled_handler => 'convert_script_to_compiled_handler', ); $aliases{$_} = $parent . quot;::quot; . $aliases{$_} for keys %aliases; __PACKAGE__->install_aliases(%aliases); Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 52. CGI emulation • It’s an emulation • It ain’t the real thing • things can go wonky Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 53. I remember #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 54. #!/usr/bin/perl I remember use CGI; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF $> GET http://localhost:8529/cgi-bin/count.pl counted 1 $> GET http://localhost:8529/cgi-bin/count.pl counted 1 $> GET http://localhost:8529/cgi-bin/count.pl counted 1 Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 55. #!/usr/bin/perl I remember use CGI; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF $> GET http://localhost:8529/registry/count.pl counted 1 $> GET http://localhost:8529/registry/count.pl counted 2 $> GET http://localhost:8529registry/count.pl counted 3 $> GET http://localhost:8529registry/count.pl counted 1 $> GET http://localhost:8529registry/count.pl counted 4 Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 56. That can’t be right? #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 57. That can’t be right? • Code is cached • Perl sticks around • Great for speed • Globals are suddently VERY GLOBAL Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 58. That can’t be right? #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 59. That can’t be right? #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header('text/plain'); $main::counter++; # GLOBAL! print <<quot;EOFquot;; counted $counter EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 60. That can be right! #!/usr/bin/perl use CGI; my $counter; my $q = new CGI; print $q->header('text/plain'); $counter++; print <<quot;EOFquot;; counted $counter EOF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 61. Globals will stick • Globals will stick around • Use my • Try ModPerl::PerlRun Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 62. CGI emulation • It’s an emulation • It ain’t the real thing • things can go wonky Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 63. I still remember #!/usr/bin/perl $> GET http://localhost:8529/registry/count.pl Counter: 1 use CGI; $> GET http://localhost:8529/registry/count.pl use strict; use warnings; Counter: 2 $> GET http://localhost:8529/registry/count.pl my $q = new CGI; Counter: 3 my $counter; $> GET http://localhost:8529/registry/count.pl Counter: 1 print $q->header('text/plain'); $> GET http://localhost:8529/registry/count.pl Counter: 4 counter_up(); sub counter_up { $counter++; print quot;Counter: $counternquot;; } Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 64. But, what the..? • I used my so it’s not a global... • To Perl, all code lives in subroutines • mod_perl turns scripts into subroutines • subroutines can create closures Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 65. subification * #!/usr/bin/perl use CGI; use strict; use warnings; my $q = new CGI; my $counter; print $q->header('text/plain'); counter_up(); sub counter_up { $counter++; print quot;Counter: $counternquot;; } * the process of making a subroutine, obviously Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 66. subification * • subroutine needs a name • filepath is a convenient naming * the process of making a subroutine, obviously Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 67. subification * /var/www/cgi-bin/hello.pl ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_hello_2epl::handler Prefix Path Sub * the process of making a subroutine, obviously Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 68. sub subification * ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_count_2epl::handler { package ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_count_2epl; no warnings; local $0 = '/var/www/cgi-bin/count.pl’; use CGI; use strict; use warnings; my $q = new CGI; my $counter; print $q->header('text/plain'); counter_up(); sub counter_up { $counter++; print quot;Counter: $counternquot;; } } the process of making a subroutine, obviously * Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 69. closures • Closures are a Perl feature • Come to be when creating subs • Normally not an issue • mod_perl can create some without telling you • man perlref for more Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 70. I still remember #!/usr/bin/perl use CGI; 2 warning signs to look for: use strict; use warnings; globals my $q = new CGI; my $counter; error_log: print $q->header('text/plain'); Variable quot;$counterquot; will not stay shared at /var/www/cgi-bin/ counter_up(); count.pl sub counter_up { $counter++; # GLOBAL print quot;Counter: $counternquot;; } Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 71. I still remember #!/usr/bin/perl use CGI; use strict; use warnings; Just remember that globals in general are to my $q = new CGI; my $counter; print $q->header('text/plain'); watch out for counter_up($counter); sub counter_up { my $counter = shift; $counter++; # GLOBAL print quot;Counter: $counternquot;; } Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 72. Good advice • use strict; • use warnings; • avoid globals • look for hints in your error_log file Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 73. CGI emulation • It’s an emulation • It ain’t the real thing • things can go wonky Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 74. I used to work #!/usr/bin/perl #countlib.pl use CGI; use strict; use strict; my $counter = 0; use warnings; sub counter_up { require quot;countlib.plquot;; $counter++; print “Counter: $countern”; my $q = new CGI; } print $q->header('text/plain'); counter_up(); Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 75. I used to work error_log: [Sun Oct 23 21:37:44 2005] [error] Can't locate countlib.pl in @INC (@INC contains: [...]) at /var/www/cgi-bin/hello.pl line 7.n Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 76. I used to work #!/usr/bin/perl use CGI; use strict; use warnings; use Cwd; my $q = new CGI; print $q->header('text/plain'); print “Cwd: “, cwd(), “n”; $> GET http://localhost:8529/cgi-bin/cwd.pl Cwd: /var/www/cgi-bin $> GET http://localhost:8529/registry/cwd.pl Cwd: / Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 77. I used to work • mod_cgi • fork()s • chdir()s to the script’s directory Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 78. Cwd • mod_perl • doesn’t fork() • doesn’t chdir()s • could chdir()s Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 79. Cwd • Cwd() is a process proprety • Apache threaded MPMs • chdir() isn’t thread-safe • mod_perl doesn’t try to break things Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 80. Cwd • You can fix your scripts • use lib(); • require “/fully/qualfied/lib/path.pl”; Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 81. Cwd • If your MPM is Prefork: • ModPerl::RegistryPrefork • ModPerl::PerlRunPrefork Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 82. It ain’t magical! • use strict/warnings • Think about globals • watch the error_log Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 83. More info • mod_perl User’s mailing-list – http://perl.apache.org/maillist/modperl.html – <modperl@perl.apache.org> • mod_perl Developer's Cookbook – http://www.modperlcookbook.org/ • – http://www.modperlbook.org/ Practical mod_perl • – http://perl.apache.org/ mod_perl at the ASF Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/
  • 84. Thank You! Slides and bonus material: http://gozer.ectoplasm.org/talk/ Philippe M. Chiasson - http://gozer.ectoplasm.org/talks/