You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tom Williams <to...@comcast.net> on 2006/06/08 09:11:05 UTC
Question about mod_perl 2 and Perl CGI form processor
Hi! I'm implementing a Novice Forms HTML form processing script:
http://www.noviceforms.com/
on a site hosted on a Apache/2.0.55 (Unix) PHP/4.3.11 mod_perl/2.0.2
Perl/v5.8.8 server. The script runs fine but I notice a strange
side-effect. When I fill out the form and the corresponding e-mail is
sent, all is well. If I fill out the form again and change some of the
info, the corresponding e-mail that is sent has the contents of the
first form submission AND the second form submission. This repeats each
time I fill out the form and send it.
Now, I'm using the worker Apache 2 MPM:
http://httpd.apache.org/docs/2.0/mod/worker.html
and I noticed I'm not getting a new worker process after the form is
sent, which is possibly fine. I'm suspecting the Apache process where
the script ran is hanging out and contains the old form data in its
environment so that when I submit a new form, the new form data is
appended in the same environment the previously run form ran in. Make sense?
Is any of this related to mod_perl or is this an Apache 2 worker MPM issue?
Thanks!
Peace...
Tom
Re: Question about mod_perl 2 and Perl CGI form processor
Posted by Tom Williams <to...@comcast.net>.
Jonathan wrote:
>
> On Jun 8, 2006, at 3:11 AM, Tom Williams wrote:
>
>> and I noticed I'm not getting a new worker process after the form is
>> sent, which is possibly fine. I'm suspecting the Apache process
>> where the script ran is hanging out and contains the old form data in
>> its environment so that when I submit a new form, the new form data
>> is appended in the same environment the previously run form ran in.
>> Make sense?
>>
>> Is any of this related to mod_perl or is this an Apache 2 worker MPM
>> issue?
>
> its because you're running a poorly written cgi-script in mod_perl.
> chances are it doesn't 'use strict' or warning, and it doesn't
> instantiate any or all variables with a scope.
>
> i can't seem to find it in the docs... it was well documented in 1.x,
> maybe the text lost its way into 2.x?
>
> in any event...
>
> the apache processes isn't hanging out, its doing what it should:
> since mp compiles and caches code to be a persistant environment and
> doesn't 'exit', if a variable is left unscoped or poorly scoped, it's
> not destroyed before the next run.
>
> bad example, but:
>
> script A:
> if ( $a ) { $a+= 1 }
>
> script B:
> my $a;
> if ( $a ) { $a+= 1 }
>
> in script A, every time mp is run, $a is incremented. a is never set
> to 0., so it just += from the last value (which was $a at the end of
> the last request )
> in script B, every time mp is run, $a is initialized (my $a )
>
> in order to get your expected behavior, you'll have to 'use strict'
> and go through the code you downloaded making sure everything is
> scoped right, using my/our/local and blocks as necessary.
>
> make sure you initialize/instantiate all of your variables or just
> expect thigns to not work.
Gotcha. Thanks for the info. When I mentioned "hanging out" above, I
didn't mean "hang" like process misbehavior but in the casual
"remaining around" sense. Sorry for the confusion. :)
I understand what's going on and will look into this. Thanks!
> that said...
>
> running mod_php and mod_perl together is a nightmare in terms of
> memory management. my advice is don't do that. push the php out via
> fastcgi , proxy it to lighty/fastcgi, or run apache on different
> ports- one with mod_php loaded, and the other with mod_perl.
I'll look into this as well.
> see:
>
> http://perl.apache.org/docs/2.0/user/coding/coding.html#Cleaning_up
> http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my____Scoped_Variable_in_Nested_Subroutines
Great!
Peace...
Tom
Re: Question about mod_perl 2 and Perl CGI form processor
Posted by Jonathan <mo...@2xlp.com>.
On Jun 8, 2006, at 3:11 AM, Tom Williams wrote:
> and I noticed I'm not getting a new worker process after the form
> is sent, which is possibly fine. I'm suspecting the Apache process
> where the script ran is hanging out and contains the old form data
> in its environment so that when I submit a new form, the new form
> data is appended in the same environment the previously run form
> ran in. Make sense?
>
> Is any of this related to mod_perl or is this an Apache 2 worker
> MPM issue?
its because you're running a poorly written cgi-script in mod_perl.
chances are it doesn't 'use strict' or warning, and it doesn't
instantiate any or all variables with a scope.
i can't seem to find it in the docs... it was well documented in 1.x,
maybe the text lost its way into 2.x?
in any event...
the apache processes isn't hanging out, its doing what it should:
since mp compiles and caches code to be a persistant environment and
doesn't 'exit', if a variable is left unscoped or poorly scoped, it's
not destroyed before the next run.
bad example, but:
script A:
if ( $a ) { $a+= 1 }
script B:
my $a;
if ( $a ) { $a+= 1 }
in script A, every time mp is run, $a is incremented. a is never set
to 0., so it just += from the last value (which was $a at the end of
the last request )
in script B, every time mp is run, $a is initialized (my $a )
in order to get your expected behavior, you'll have to 'use strict'
and go through the code you downloaded making sure everything is
scoped right, using my/our/local and blocks as necessary.
make sure you initialize/instantiate all of your variables or just
expect thigns to not work.
that said...
running mod_php and mod_perl together is a nightmare in terms of
memory management. my advice is don't do that. push the php out via
fastcgi , proxy it to lighty/fastcgi, or run apache on different
ports- one with mod_php loaded, and the other with mod_perl.
see:
http://perl.apache.org/docs/2.0/user/coding/coding.html#Cleaning_up
http://perl.apache.org/docs/general/perl_reference/
perl_reference.html#my____Scoped_Variable_in_Nested_Subroutines
//Jonathan Vanasco
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
| RoadSound.com / Indie-Rock.net
| Collaborative Online Management And Syndication Tools
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -