Loading ...
Sorry, an error occurred while loading the content.

Question about Files directive

Expand Messages
  • Jain, Abhay K, ALABS
    I just compiled mod_perl 1.29 with apache. As I understand from the documentation that with use of directive Files , Apache caches the perl cgi code so that
    Message 1 of 16 , Mar 2, 2005
    • 0 Attachment
      I just compiled mod_perl 1.29 with apache. As I understand from
      the documentation that with use of directive "Files", Apache caches the
      perl cgi code so that on next invocation it does not to reparse it.
      If I want to specify more than one cgi script to be cached, how
      do I specify via Files directive.
    • Sean Davis
      ... I don t think just a files directive will do it. You probably need to read--it is worth the read: http://perl.apache.org/docs/1.0/guide/porting.html Sean
      Message 2 of 16 , Mar 2, 2005
      • 0 Attachment
        On Mar 2, 2005, at 9:37 AM, Jain, Abhay K, ALABS wrote:

        > I just compiled mod_perl 1.29 with apache. As I understand from
        > the documentation that with use of directive "Files", Apache caches the
        > perl cgi code so that on next invocation it does not to reparse it.
        > If I want to specify more than one cgi script to be cached, how
        > do I specify via Files directive.
        >
        >
        I don't think just a files directive will do it. You probably need to
        read--it is worth the read:

        http://perl.apache.org/docs/1.0/guide/porting.html

        Sean
      • Jain, Abhay K, ALABS
        ... From: Sean Davis [mailto:sdavis2@mail.nih.gov] Sent: Wednesday, March 02, 2005 9:43 AM To: Jain, Abhay K, ALABS Cc: modperl@perl.apache.org Subject: Re:
        Message 3 of 16 , Mar 2, 2005
        • 0 Attachment
          -----Original Message-----
          From: Sean Davis [mailto:sdavis2@...]
          Sent: Wednesday, March 02, 2005 9:43 AM
          To: Jain, Abhay K, ALABS
          Cc: modperl@...
          Subject: Re: Question about Files directive



          On Mar 2, 2005, at 9:37 AM, Jain, Abhay K, ALABS wrote:

          > I just compiled mod_perl 1.29 with apache. As I understand from
          > the documentation that with use of directive "Files", Apache caches
          the
          > perl cgi code so that on next invocation it does not to reparse it.
          > If I want to specify more than one cgi script to be cached, how
          > do I specify via Files directive.
          >
          >
          I don't think just a files directive will do it. You probably need to
          read--it is worth the read:

          http://perl.apache.org/docs/1.0/guide/porting.html

          Sean
          --

          Thanks. I should have stated some thing. I already have lots of .cgi
          scripts
          written in Perl and have been running under Netscape. Initial idea is to
          run
          them as is. Some heavy hitter scripts are simple and well written.
          My question was based in the context of the Files block
          from the following from http://perl.apache.org/start/tips/registry.html

          file:hello.cgi
          --------------
          #!/usr/local/bin/perl -w
          use strict;
          use CGI;
          my $q = CGI->new;
          print $q->header,
          $q->start_html,
          $q->h1('Hello World!'),
          $q->end_html;
          This script can now be run as-is under Apache::Registry by using the
          following configuration in httpd.conf:

          <Files hello.cgi>
          SetHandler perl-script
          PerlHandler Apache::Registry
          Options ExecCGI
          </Files>
        • Markus Wichitill
          ... mod_perl always caches everything it executes, whether you want it or not. Files/Directory/Location blocks are just possible ways to specify what it is
          Message 4 of 16 , Mar 2, 2005
          • 0 Attachment
            Jain, Abhay K, ALABS wrote:
            > I just compiled mod_perl 1.29 with apache. As I understand from
            > the documentation that with use of directive "Files", Apache caches the
            > perl cgi code so that on next invocation it does not to reparse it.
            > If I want to specify more than one cgi script to be cached, how
            > do I specify via Files directive.

            mod_perl always caches everything it executes, whether you want it or not.
            Files/Directory/Location blocks are just possible ways to specify what it is
            supposed to execute.
          • Goehring, Chuck, RCI - San Diego
            Jain, If you are using mod_perl (Registry) and the bulk of the code can be moved to module files, minimizing of parsing is automatic. When the code is in
            Message 5 of 16 , Mar 2, 2005
            • 0 Attachment
              Jain,

              If you are using mod_perl (Registry) and the bulk of the code can be moved to module files, minimizing of parsing is automatic. When the code is in modules, only the "top level" script that creates & uses the objects gets compiled each time - the ".pm" files are only parsed once.

              Per the docs at http://httpd.apache.org/docs/mod/core.html#files, "The <Files> directive provides for access control by filename." This directive is not perl/mod_perl "aware" so is not what you are looking for. By "access control" they mean security.

              Chuck

              -----Original Message-----
              From: Jain, Abhay K, ALABS [mailto:jainabhay@...]
              Sent: Wed 3/2/2005 6:37 AM
              To: modperl@...
              Cc:
              Subject: Question about Files directive



              I just compiled mod_perl 1.29 with apache. As I understand from
              the documentation that with use of directive "Files", Apache caches the
              perl cgi code so that on next invocation it does not to reparse it.
              If I want to specify more than one cgi script to be cached, how
              do I specify via Files directive.
            • Tom Schindl
              ... Since when is that the case. You can of course use the Files-directive to tell Apache that it should not use the default content handler but instead your
              Message 6 of 16 , Mar 2, 2005
              • 0 Attachment
                Goehring, Chuck, RCI - San Diego wrote:
                > Jain,
                >
                > If you are using mod_perl (Registry) and the bulk of the code can be moved to module files, minimizing of parsing is automatic. When the code is in modules, only the "top level" script that creates & uses the objects gets compiled each time - the ".pm" files are only parsed once.
                >
                > Per the docs at http://httpd.apache.org/docs/mod/core.html#files, "The <Files> directive provides for access control by filename." This directive is not perl/mod_perl "aware" so is not what you are looking for. By "access control" they mean security.
                >

                Since when is that the case. You can of course use the Files-directive
                to tell Apache that it should not use the default content handler but
                instead your own (e.g. mod_perl,mod_php,...)

                <Files ~ "\.fastperl">
                SetHandler perl-script
                PerlHandler My::FastModPerlModule
                </Files>

                With this directive in use every file ending in .fastperl will be
                handled by my custom-content handler instead of the default one.

                Tom
              • Goehring, Chuck, RCI - San Diego
                Yeah, you win. But my point was that making a module is the way to reduce parsing. An ordinary cgi script would be parsed every time regardless of the
                Message 7 of 16 , Mar 2, 2005
                • 0 Attachment
                  Yeah, you win. But my point was that making a module is the way to reduce parsing. An ordinary cgi script would be parsed every time regardless of the container used to specify the handler. In your example you indicate the use of a module as well.

                  Anyway, sorry for the lack of clarity.

                  Chuck


                  -----Original Message-----
                  From: Tom Schindl [mailto:tomAtLinux@...]
                  Sent: Wed 3/2/2005 7:51 AM
                  To: Goehring, Chuck, RCI - San Diego
                  Cc: Jain, Abhay K, ALABS; modperl@...
                  Subject: Re: Question about Files directive



                  Goehring, Chuck, RCI - San Diego wrote:
                  > Jain,
                  >
                  > If you are using mod_perl (Registry) and the bulk of the code can be moved to module files, minimizing of parsing is automatic. When the code is in modules, only the "top level" script that creates & uses the objects gets compiled each time - the ".pm" files are only parsed once.
                  >
                  > Per the docs at http://httpd.apache.org/docs/mod/core.html#files, "The <Files> directive provides for access control by filename." This directive is not perl/mod_perl "aware" so is not what you are looking for. By "access control" they mean security.
                  >

                  Since when is that the case. You can of course use the Files-directive
                  to tell Apache that it should not use the default content handler but
                  instead your own (e.g. mod_perl,mod_php,...)

                  <Files ~ "\.fastperl">
                  SetHandler perl-script
                  PerlHandler My::FastModPerlModule
                  </Files>

                  With this directive in use every file ending in .fastperl will be
                  handled by my custom-content handler instead of the default one.

                  Tom
                • Perrin Harkins
                  ... If you change hello.cgi to *.cgi, then all files ending in .cgi will be run through Apache::Registry. Is that what you were looking for? - Perrin
                  Message 8 of 16 , Mar 2, 2005
                  • 0 Attachment
                    On Wed, 2005-03-02 at 08:51 -0600, Jain, Abhay K, ALABS wrote:
                    > <Files hello.cgi>
                    > SetHandler perl-script
                    > PerlHandler Apache::Registry
                    > Options ExecCGI
                    > </Files>

                    If you change hello.cgi to *.cgi, then all files ending in .cgi will be
                    run through Apache::Registry. Is that what you were looking for?

                    - Perrin
                  • Perrin Harkins
                    On Wed, 2005-03-02 at 08:16 -0800, Goehring, Chuck, RCI - San Diego ... Not to gang up on you, Chuck, but the question was about running things under
                    Message 9 of 16 , Mar 2, 2005
                    • 0 Attachment
                      On Wed, 2005-03-02 at 08:16 -0800, Goehring, Chuck, RCI - San Diego
                      wrote:
                      > An ordinary cgi script would be parsed every time regardless of the
                      > container used to specify the handler.

                      Not to gang up on you, Chuck, but the question was about running things
                      under Apache::Registry, so the script would not be parsed every time.
                      A::R does a stat on the file every time, but doesn't parse it again
                      unless it has changed.

                      Scripts are parsed every time when running under CGI instead of
                      mod_perl, but in that case the modules are parsed every time too.

                      - Perrin
                    • Goehring, Chuck, RCI - San Diego
                      Well, when I use cgis that run under Registry, if I modify a pm file, I have to restart the web server before I see changes. If I modify the top level cgi, I
                      Message 10 of 16 , Mar 2, 2005
                      • 0 Attachment
                        Well, when I use cgis that run under Registry, if I modify a pm file, I have to restart the web server before I see changes. If I modify the top level cgi, I don't have to restart the web server. This tells me the modules are parsed only the first time and the top level cgi is parsed every time it runs. So, for my setup, using mod_perl does not reduce reparsing if my code is not in modules.

                        Hope this clarifies.

                        Chuck

                        -----Original Message-----
                        From: Perrin Harkins [mailto:perrin@...]
                        Sent: Wed 3/2/2005 8:26 AM
                        To: Goehring, Chuck, RCI - San Diego
                        Cc: modperl@...
                        Subject: RE: Question about Files directive



                        On Wed, 2005-03-02 at 08:16 -0800, Goehring, Chuck, RCI - San Diego
                        wrote:
                        > An ordinary cgi script would be parsed every time regardless of the
                        > container used to specify the handler.

                        Not to gang up on you, Chuck, but the question was about running things
                        under Apache::Registry, so the script would not be parsed every time.
                        A::R does a stat on the file every time, but doesn't parse it again
                        unless it has changed.

                        Scripts are parsed every time when running under CGI instead of
                        mod_perl, but in that case the modules are parsed every time too.

                        - Perrin
                      • Perrin Harkins
                        On Wed, 2005-03-02 at 08:36 -0800, Goehring, Chuck, RCI - San Diego ... It just checks the modification time to see if it should be re-parsed. It doesn t
                        Message 11 of 16 , Mar 2, 2005
                        • 0 Attachment
                          On Wed, 2005-03-02 at 08:36 -0800, Goehring, Chuck, RCI - San Diego
                          wrote:
                          > If I modify the top level cgi, I don't have to restart the web server.
                          > This tells me the modules are parsed only the first time and the top
                          > level cgi is parsed every time it runs. So, for my setup, using
                          > mod_perl does not reduce reparsing if my code is not in modules.

                          It just checks the modification time to see if it should be re-parsed.
                          It doesn't re-parse it on every request. This section explains it in
                          more detail:
                          http://perl.apache.org/docs/1.0/guide/intro.html#Apache__Registry

                          - Perrin
                        • Carl Johnstone
                          Hi, To explain exactly what is going on... The Files directive is an *apache* not mod_perl directive. You can use it within apache to define specific rules
                          Message 12 of 16 , Mar 2, 2005
                          • 0 Attachment
                            Hi,

                            To explain exactly what is going on...

                            The "Files" directive is an *apache* not mod_perl directive. You can use it
                            within apache to define specific rules for a file (or bunch of files).

                            The "SetHandler" directive is also an apache directive, that tells apache
                            what hander should be used.

                            So for instance this:

                            <Files *.cgi>
                            SetHandler perl-script
                            </Files>

                            tells apache that all files matching *.cgi should be handled by perl-script
                            which is mod_perl.

                            The "PerlHandler" directive is mod_perl, it tells mod_perl which perl module
                            should be used as the handler.

                            In the case of Apache::Registry this is a perl module that attempts to
                            provide some of the advantages of mod_perl to regular cgi scripts. In
                            particular you get use of the built-in perl interpreter, and your perl files
                            are only interpreted when they are changed rather than everytime they are
                            requested. This is the "cache" that you referred to in your first post.

                            The "Options" directive sets permissions, in this case it allows files to be
                            executed as CGI. This option is also required by Apache::Registry.


                            Now you'll have to be very careful as you're not really caching CGI scripts.
                            The Apache::Registry module does a reasonable job of making things works,
                            but there are issues to be wary of. The "porting" page that's already been
                            suggested lists all the pitfalls.

                            You may also want to investigate Apache::PerlRun. This is similar to
                            Apache::Registry in that it uses the built-in perl interpreter but it
                            reloads the script on every request. This means that it doesn't give the
                            same performance benefit that Apache::Registry does, but on the other hand
                            it's immune to some of the problems.

                            Hope this answers your question.

                            Carl
                          • Carl Johnstone
                            CCing it back onto the list... ... Now if I do not want all to specify all cgi scripts (*.cgi) to be handled by the handler precisely to avoid pitfalls and
                            Message 13 of 16 , Mar 2, 2005
                            • 0 Attachment
                              CCing it back onto the list...

                              >>>>>
                              Now if I do not want all to specify
                              all cgi scripts (*.cgi) to be handled by the handler
                              precisely to avoid pitfalls and only specify
                              some files to be used, then how do I do
                              that via the Files directive.
                              <<<<<

                              There's a couple of different approaches.

                              The first you posted - list them individually. Alternatively the Files
                              directive will take a regular expression. The apache docs are here for v1.3
                              http://httpd.apache.org/docs/mod/core.html#files

                              Another way if all your cgi scripts are in a single cgi-bin or similar is to
                              setup different aliases. Then you can access the same scripts as straight
                              CGI, Apache::Registry, or Apache::PerlRun. I'll assume your cgi-bin is
                              already setup - here's the rest of the config.

                              Alias /perl/ /path/to/cgi-bin/
                              PerlModule Apache::Registry
                              <Location /perl>
                              SetHander perl-script
                              PerlHandler Apache::Registry
                              Options ExecCGI
                              allow from all
                              PerlSendHeader On
                              </Location>

                              Alias /perl-cgi/ /path/to/cgi-bin/
                              PerlModule Apache::PerlRun
                              <Location /perl-cgi>
                              SetHander perl-script
                              PerlHandler Apache::PerlRun
                              Options ExecCGI
                              allow from all
                              PerlSendHeader On
                              </Location>


                              Then you can try running your script through Apache::Registry with
                              http://www.mydomain.com/perl/myscript.cgi if that doesn't work then
                              http://www.mydomain.com/perl-cgi/myscript.cgi for Apache::PerlRun. Failing
                              any of those revert back to CGI with
                              http://www.mydomain.com/cgi-bin/myscipt.cgi.


                              Carl
                            • Stas Bekman
                              ... Chuck, use Apache::Reload and you won t have to restart the server. http://modperlbook.org/html/ch06_08.html --
                              Message 14 of 16 , Mar 2, 2005
                              • 0 Attachment
                                Goehring, Chuck, RCI - San Diego wrote:
                                >
                                > Well, when I use cgis that run under Registry, if I modify a pm file,
                                > I have to restart the web server before I see changes.

                                Chuck, use Apache::Reload and you won't have to restart the server.
                                http://modperlbook.org/html/ch06_08.html

                                --
                                __________________________________________________________________
                                Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
                                http://stason.org/ mod_perl Guide ---> http://perl.apache.org
                                mailto:stas@... http://use.perl.org http://apacheweek.com
                                http://modperlbook.org http://apache.org http://ticketmaster.com
                              • Goehring, Chuck, RCI - San Diego
                                Thanks, you always have the answer. ... From: Stas Bekman [mailto:stas@stason.org] Sent: Wed 3/2/2005 3:53 PM To: Goehring, Chuck, RCI - San Diego Cc: Perrin
                                Message 15 of 16 , Mar 2, 2005
                                • 0 Attachment
                                  Thanks, you always have the answer.


                                  -----Original Message-----
                                  From: Stas Bekman [mailto:stas@...]
                                  Sent: Wed 3/2/2005 3:53 PM
                                  To: Goehring, Chuck, RCI - San Diego
                                  Cc: Perrin Harkins; modperl@...
                                  Subject: Re: Question about Files directive



                                  Goehring, Chuck, RCI - San Diego wrote:
                                  >
                                  > Well, when I use cgis that run under Registry, if I modify a pm file,
                                  > I have to restart the web server before I see changes.

                                  Chuck, use Apache::Reload and you won't have to restart the server.
                                  http://modperlbook.org/html/ch06_08.html

                                  --
                                  __________________________________________________________________
                                  Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
                                  http://stason.org/ mod_perl Guide ---> http://perl.apache.org
                                  mailto:stas@... http://use.perl.org http://apacheweek.com
                                  http://modperlbook.org http://apache.org http://ticketmaster.com
                                • Carl Johnstone
                                  ... Although on a production server that s dealing with many thousands of requests, that could be an awful lot of checks to see if modules have been updated.
                                  Message 16 of 16 , Mar 2, 2005
                                  • 0 Attachment
                                    > Chuck, use Apache::Reload and you won't have to restart the server.
                                    > http://modperlbook.org/html/ch06_08.html


                                    Although on a production server that's dealing with many thousands of
                                    requests, that could be an awful lot of checks to see if modules have been
                                    updated. Personally I prefer a bit of shell scripting on a cron:

                                    #!/bin/sh

                                    if [ -n "`find /path/to/my/modules -prune -newer /path/to/apache.pid`" ];
                                    then
                                    echo "apache needs reloading"
                                    echo "Testing"
                                    apachectl configtest
                                    if [ $? = 0 ] ; then
                                    echo "Restarting"
                                    apachectl restart
                                    else
                                    echo "ERROR in apache config"
                                    fi
                                    fi



                                    --
                                    Carl
                                  Your message has been successfully submitted and would be delivered to recipients shortly.