Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl CGI script returns different results depending on run

Tags:

apache

cgi

perl

I have a Perl CGI script that emits different HTML apparently randomly. None of the inputs change. E.g., I will run wget twice and get two different results. The CGI is backed by a development database that, too, doesn't change.

I have a debug statement that informs me that the same number of elements are returned from the DB into the script.

Frankly, I'm mystified. Logic, DB, and inputs don't change, but the output does.

The http server is apache2 on Ubuntu 10.04. Perl version is perl 5.10.

edit: whenever I run it from the command-line on the server, the output is correct.

edit2: some of the bad runs seem like prior versions of the script. I don't think Apache is caches CGIs, but it seems like it might be grabbing out-of-date cache versions....

like image 793
Paul Nathan Avatar asked Jul 02 '10 21:07

Paul Nathan


1 Answers

Is your CGI script being run using Apache's standard CGI API or are you running it under mod_perl using the Apache::Registry (or ModPerl::Registry in Apache2) CGI emulation layer?

I have seen an effect similar to the one you describe, which results from the way mod_perl's CGI emulation works. The details are discussed here.

One workaround is to take any 'global' variables declared at the start of the script with 'my' and change the keyword 'my' to 'our'.

Of course your problem may be something completely different - it's very hard to say without more information.

like image 138
Grant McLean Avatar answered Sep 25 '22 02:09

Grant McLean