You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Aliet Santiesteban Sifontes <al...@tesla.cujae.edu.cu> on 2005/09/22 01:09:12 UTC

how to avoid the caching of the executed perl file

Hi list, I have a  problem with a .pl script, the scripts is executed in 
the first request, and it's been cached by the server, I call this 
script passing different arguments, and I expect that it must be 
executed with the new args but, I'm having the same output from the 
first execution wich seems to be cached by the server, not the browser, 
if I restart the server works with the new args, how to avoid this???
Best regards





Re: how to avoid the caching of the executed perl file

Posted by Aliet Santiesteban Sifontes <al...@tesla.cujae.edu.cu>.
Tom, thank's a lot, I'm going to test it right now, I tell you later.
Best Regards
Tom Schindl wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ok. The offending code is this:
>
> - --------------------8<--------------------
> use strict;
>
> my $cgi;
> my %params;
> # my ....
>
> sub getDataFromListCode {
>    $params{"Filtro1"}= "";
>    $params{"Filtro2"}= "";
>    $params{"Filtro3"}= "";
>    $params{"Filtro4"}= "";
>    # .....
> }
> - --------------------8<--------------------
>
> the real code after registry has loaded it looks like this:
>
> - --------------------8<--------------------
> sub run {
>    use strict;
>
>    my $cgi;
>    my %params;
>    # my ....
>
>    sub getDataFromListCode {
>       $params{"Filtro1"}= "";
>       $params{"Filtro2"}= "";
>       $params{"Filtro3"}= "";
>       $params{"Filtro4"}= "";
>       # ....
>    }
> }
> - --------------------8<--------------------
>
> These are closures to variables and so they won't change their values
> after the first execution. Couldn't you just move all variables defined
> before "sub getDataFromListCode {}" inside the sub or another idea is
> the you make real globals from them using "use vars" or $main::cgi for
> variable names.
>
> Corrected code would look like this:
>
> - --------------------8<--------------------
> use strict;
> use vars( $cgi, %params );
>
> $cgi = new CGI();
> %params{"bla"} = "blo";
>
> sub getDataFromListCode {
>    $params{"Filtro1"}= "";
>    $params{"Filtro2"}= "";
>    $params{"Filtro3"}= "";
>    $params{"Filtro4"}= "";
>    # ....
> }
> - --------------------8<--------------------
>
>
> For more information look here:
> http://perl.apache.org/docs/general/perl_reference/perl_reference.html
>
> Generally it's not good practice to use global variables in sub-routines
> you should pass them to them. If you need globals you should declare
> them using use vars(). The difference is explained in the url above.
>
>
> Tom
>
> Aliet Santiesteban Sifontes wrote:
>   
>> Tom , at this link you can find the scripts, problematic is Listing.pl,
>> don't blame me for the bad code, I'm just trying to fix it, is a very
>> old apps:
>> http://sflcujae.cujae.edu.cu/perl/
>>
>> Tom Schindl wrote:
>>
>> Aliet Santiesteban Sifontes wrote:
>>  
>>
>>     
>>>>> The problem was solved using
>>>>>
>>>>> ModPerl::PerlRun
>>>>>
>>>>>     
>>>>>           
>> I'd suggest to get better performance to switch back to
>> ModPerl::Registry. You have shown us many lines of code but not the one
>> which shows how your problem is created. I suppose you are creating a
>> closure to $cgi and that's why it is cached and not renewed on every
>> request.
>>
>> Show us the lines where you are defining variables like $cgi and we can
>> proof whether I'm right or wrong.
>>
>> Tom
>>
>>     
>>>
>>>
>>>       
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (GNU/Linux)
> Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
>
> iD8DBQFDM7PhkVPeOFLgZFIRAotOAJsEeytqL9TnYZcB1aCN/MqM+u24swCePsNy
> 0I6urn4IPpkKm3jHwGFAgCI=
> =ph6u
> -----END PGP SIGNATURE-----
>
>
>
>
>   






Re: how to avoid the caching of the executed perl file

Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok. The offending code is this:

- --------------------8<--------------------
use strict;

my $cgi;
my %params;
# my ....

sub getDataFromListCode {
   $params{"Filtro1"}= "";
   $params{"Filtro2"}= "";
   $params{"Filtro3"}= "";
   $params{"Filtro4"}= "";
   # .....
}
- --------------------8<--------------------

the real code after registry has loaded it looks like this:

- --------------------8<--------------------
sub run {
   use strict;

   my $cgi;
   my %params;
   # my ....

   sub getDataFromListCode {
      $params{"Filtro1"}= "";
      $params{"Filtro2"}= "";
      $params{"Filtro3"}= "";
      $params{"Filtro4"}= "";
      # ....
   }
}
- --------------------8<--------------------

These are closures to variables and so they won't change their values
after the first execution. Couldn't you just move all variables defined
before "sub getDataFromListCode {}" inside the sub or another idea is
the you make real globals from them using "use vars" or $main::cgi for
variable names.

Corrected code would look like this:

- --------------------8<--------------------
use strict;
use vars( $cgi, %params );

$cgi = new CGI();
%params{"bla"} = "blo";

sub getDataFromListCode {
   $params{"Filtro1"}= "";
   $params{"Filtro2"}= "";
   $params{"Filtro3"}= "";
   $params{"Filtro4"}= "";
   # ....
}
- --------------------8<--------------------


For more information look here:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html

Generally it's not good practice to use global variables in sub-routines
you should pass them to them. If you need globals you should declare
them using use vars(). The difference is explained in the url above.


Tom

Aliet Santiesteban Sifontes wrote:
> 
> Tom , at this link you can find the scripts, problematic is Listing.pl,
> don't blame me for the bad code, I'm just trying to fix it, is a very
> old apps:
> http://sflcujae.cujae.edu.cu/perl/
> 
> Tom Schindl wrote:
> 
> Aliet Santiesteban Sifontes wrote:
>  
> 
>>>> The problem was solved using
>>>>
>>>> ModPerl::PerlRun
>>>>
>>>>     
> 
> 
> I'd suggest to get better performance to switch back to
> ModPerl::Registry. You have shown us many lines of code but not the one
> which shows how your problem is created. I suppose you are creating a
> closure to $cgi and that's why it is cached and not renewed on every
> request.
> 
> Show us the lines where you are defining variables like $cgi and we can
> proof whether I'm right or wrong.
> 
> Tom
> 
>>
>>
>>
>>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFDM7PhkVPeOFLgZFIRAotOAJsEeytqL9TnYZcB1aCN/MqM+u24swCePsNy
0I6urn4IPpkKm3jHwGFAgCI=
=ph6u
-----END PGP SIGNATURE-----

Re: how to avoid the caching of the executed perl file

Posted by Aliet Santiesteban Sifontes <al...@tesla.cujae.edu.cu>.
Tom , at this link you can find the scripts, problematic is Listing.pl, 
don't blame me for the bad code, I'm just trying to fix it, is a very 
old apps:
http://sflcujae.cujae.edu.cu/perl/

Tom Schindl wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Aliet Santiesteban Sifontes wrote:
>   
>> The problem was solved using
>>
>> ModPerl::PerlRun
>>
>>     
>
> I'd suggest to get better performance to switch back to
> ModPerl::Registry. You have shown us many lines of code but not the one
> which shows how your problem is created. I suppose you are creating a
> closure to $cgi and that's why it is cached and not renewed on every
> request.
>
> Show us the lines where you are defining variables like $cgi and we can
> proof whether I'm right or wrong.
>
> Tom
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (GNU/Linux)
> Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
>
> iD8DBQFDMnPtkVPeOFLgZFIRAsRnAJ9d4hZoLKgidDR5slRFMVJDJzRe3wCfR5Jc
> wkYO8mYtqc4DcGMmXPIwSsc=
> =MS7w
> -----END PGP SIGNATURE-----
>
>
>
>
>   






Re: how to avoid the caching of the executed perl file

Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aliet Santiesteban Sifontes wrote:
> The problem was solved using
> 
> ModPerl::PerlRun
> 

I'd suggest to get better performance to switch back to
ModPerl::Registry. You have shown us many lines of code but not the one
which shows how your problem is created. I suppose you are creating a
closure to $cgi and that's why it is cached and not renewed on every
request.

Show us the lines where you are defining variables like $cgi and we can
proof whether I'm right or wrong.

Tom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFDMnPtkVPeOFLgZFIRAsRnAJ9d4hZoLKgidDR5slRFMVJDJzRe3wCfR5Jc
wkYO8mYtqc4DcGMmXPIwSsc=
=MS7w
-----END PGP SIGNATURE-----

Re: how to avoid the caching of the executed perl file

Posted by Aliet Santiesteban Sifontes <al...@tesla.cujae.edu.cu>.
The problem was solved using

ModPerl::PerlRun

Thank's a lot
Malcolm J Harwood wrote:
> On Wednesday 21 September 2005 08:10 pm, Aliet Santiesteban Sifontes wrote:
>
>   
>>> On Wednesday 21 September 2005 07:09 pm, Aliet Santiesteban Sifontes 
>>>       
> wrote:
>   
>>>> Hi list, I have a  problem with a .pl script, the scripts is executed in
>>>> the first request, and it's been cached by the server, I call this
>>>> script passing different arguments, and I expect that it must be
>>>> executed with the new args but, I'm having the same output from the
>>>> first execution wich seems to be cached by the server, not the browser,
>>>> if I restart the server works with the new args, how to avoid this???
>>>>         
>
>   
>>      PerlResponseHandler ModPerl::Registry
>>     
>
> Is that deliberate? Any globals will persist between connections.
>
> If you use ModPerl::PerlRun does the problem go away?
>
>   
>> The script does some database queries, later just list it:
>> use strict;
>> use DBI;
>> use CGI;
>> use CGI::Carp qw(fatalsToBrowser);
>> use lib::Master;
>> # Let's require session stuff
>> use lib::SessionUtil;
>> ...
>> print $cgi->header,                    # create the HTTP header
>>          $cgi->start_html(-onload=>"if ($isInvitado==1){
>>                                        top.Nav='".${$config}{"nav"}."';
>>                                     };
>>                                     if (top.Nav > '' ) {
>>
>> top.frames.Navigation.location.href=top.Nav;
>>                                    top.Nav='';
>>                                      };
>>                                      top.CountRows=$NumRows;
>>                                      top.isRow=$isRow;
>>
>> top.CantRows=".${$config}{"CantRows"}.";
>>
>> top.frames.Path.location.href='".${$config}{"path"}."';
>>
>> top.isTitleLeft='".${$config}{"LeftTitle"}."';
>>
>> top.isTitleRight='".${$config}{"RightTitle"}."';
>>                                      top.setTitle();
>>                                      top.ListCode='$ListCode';
>>                                      top.Level = '".${$config}{"Level"}."';
>>                                      top.Origen = '$Origen';
>>                                      top.IDAux = '$ID';
>>                                      top.Filtro='$Filtro';
>>
>> top.Parame[".${$config}{"Level"}."]='$Parametro';");
>> blaablala...
>> ....end_html...
>>     
>
> Where are you getting the data in this? It doesn't look like it's your output 
> code.
>
> Check you are reinitialising any globals you might have. Check for closures in 
> your data acquisition code.
>
>
>
>
>   





Re: how to avoid the caching of the executed perl file

Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Wednesday 21 September 2005 08:10 pm, Aliet Santiesteban Sifontes wrote:

> > On Wednesday 21 September 2005 07:09 pm, Aliet Santiesteban Sifontes 
wrote:
> >> Hi list, I have a  problem with a .pl script, the scripts is executed in
> >> the first request, and it's been cached by the server, I call this
> >> script passing different arguments, and I expect that it must be
> >> executed with the new args but, I'm having the same output from the
> >> first execution wich seems to be cached by the server, not the browser,
> >> if I restart the server works with the new args, how to avoid this???

>      PerlResponseHandler ModPerl::Registry

Is that deliberate? Any globals will persist between connections.

If you use ModPerl::PerlRun does the problem go away?

> The script does some database queries, later just list it:
> use strict;
> use DBI;
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use lib::Master;
> # Let's require session stuff
> use lib::SessionUtil;
> ...
> print $cgi->header,                    # create the HTTP header
>          $cgi->start_html(-onload=>"if ($isInvitado==1){
>                                        top.Nav='".${$config}{"nav"}."';
>                                     };
>                                     if (top.Nav > '' ) {
>
> top.frames.Navigation.location.href=top.Nav;
>                                    top.Nav='';
>                                      };
>                                      top.CountRows=$NumRows;
>                                      top.isRow=$isRow;
>
> top.CantRows=".${$config}{"CantRows"}.";
>
> top.frames.Path.location.href='".${$config}{"path"}."';
>
> top.isTitleLeft='".${$config}{"LeftTitle"}."';
>
> top.isTitleRight='".${$config}{"RightTitle"}."';
>                                      top.setTitle();
>                                      top.ListCode='$ListCode';
>                                      top.Level = '".${$config}{"Level"}."';
>                                      top.Origen = '$Origen';
>                                      top.IDAux = '$ID';
>                                      top.Filtro='$Filtro';
>
> top.Parame[".${$config}{"Level"}."]='$Parametro';");
> blaablala...
> ....end_html...

Where are you getting the data in this? It doesn't look like it's your output 
code.

Check you are reinitialising any globals you might have. Check for closures in 
your data acquisition code.

Re: how to avoid the caching of the executed perl file

Posted by Aliet Santiesteban Sifontes <al...@tesla.cujae.edu.cu>.
Apache-2.0.54, mod-perl-2.0.1, ActivePerl 5.8.7.813, windows 2003 
Enterprise Server.
Apache Config:
LoadFile "D:/Perl/bin/perl58.dll"
LoadModule perl_module modules/mod_perl.so
PerlRequire "D:/Apache2/conf/includes.pl"
PerlSwitches -wT
Alias /intercompras/cgi-bin/ "D:/Apache2/htdocs/intercompras/cgi-bin/"
<Location /intercompras/cgi-bin/>
     SetHandler perl-script
     PerlResponseHandler ModPerl::Registry
     Options +ExecCGI +FollowSymLinks
     PerlOptions +ParseHeaders
</Location>

The script does some database queries, later just list it:
use strict;
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use lib::Master;
# Let's require session stuff
use lib::SessionUtil;
...
print $cgi->header,                    # create the HTTP header
         $cgi->start_html(-onload=>"if ($isInvitado==1){
                                       top.Nav='".${$config}{"nav"}."';
                                    };
                                    if (top.Nav > '' ) {
                                       
top.frames.Navigation.location.href=top.Nav;
                                   top.Nav='';
                                     };
                                     top.CountRows=$NumRows;
                                     top.isRow=$isRow;
                                     
top.CantRows=".${$config}{"CantRows"}.";
                                     
top.frames.Path.location.href='".${$config}{"path"}."';
                                     
top.isTitleLeft='".${$config}{"LeftTitle"}."';
                                     
top.isTitleRight='".${$config}{"RightTitle"}."';
                                     top.setTitle();
                                     top.ListCode='$ListCode';
                                     top.Level = '".${$config}{"Level"}."';
                                     top.Origen = '$Origen';
                                     top.IDAux = '$ID';
                                     top.Filtro='$Filtro';
                                     
top.Parame[".${$config}{"Level"}."]='$Parametro';");
blaablala...
....end_html...
Best Regards
Malcolm J Harwood wrote:
> On Wednesday 21 September 2005 07:09 pm, Aliet Santiesteban Sifontes wrote:
>
>   
>> Hi list, I have a  problem with a .pl script, the scripts is executed in
>> the first request, and it's been cached by the server, I call this
>> script passing different arguments, and I expect that it must be
>> executed with the new args but, I'm having the same output from the
>> first execution wich seems to be cached by the server, not the browser,
>> if I restart the server works with the new args, how to avoid this???
>>     
>
> We'd have to know more about what you're doing to know. (Which version of 
> apache and modperl are you using, what's your configuration, what does your 
> script actually do?)
>
> Are you using modperl? If so, which handler are you using?
> Have you checked for closures?
>
>
>
>
>   





Re: how to avoid the caching of the executed perl file

Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Wednesday 21 September 2005 07:09 pm, Aliet Santiesteban Sifontes wrote:

> Hi list, I have a  problem with a .pl script, the scripts is executed in
> the first request, and it's been cached by the server, I call this
> script passing different arguments, and I expect that it must be
> executed with the new args but, I'm having the same output from the
> first execution wich seems to be cached by the server, not the browser,
> if I restart the server works with the new args, how to avoid this???

We'd have to know more about what you're doing to know. (Which version of 
apache and modperl are you using, what's your configuration, what does your 
script actually do?)

Are you using modperl? If so, which handler are you using?
Have you checked for closures?




-- 
"Let's just say that if complete and utter chaos was lightning, he'd
be the sort to stand on a hilltop in a thunderstorm wearing wet copper
armour and shouting 'All gods are bastards'."
-- Rincewind about Twoflower, The Colour of Magic