5
votes

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....

2
Without code to examine, no one will have any idea what the issue is.Richard Simões
I'm not sure what part of the code here would matter, and I'm not able to dump the entirety of the code out here.Paul Nathan
you don't happen to have $[ = rand in your code anywhere do you :)Eric Strom
more seriously, have you tried dumping all of the environment and server variables to see if any of those are changing?Eric Strom
This question is vague and does not have enough information. You haven't stated what the inputs are, how they've changed, or what is being performed by them. --- What modules are being used? What encoding is being done? What charset is your database in? If the inputs are straight from the database, SQL could be the culprit, since ordered results aren't returned unless you use the ORDER BY clause. --- We need MORE information in order to help.vol7ron

2 Answers

5
votes

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.

0
votes

Caching: Apache probably isn't caching, but your browser may be. Turn off caching (set your browser cache to 0MB).

Command line: If your output differs from webpage to CLI execution of the script, then it seems like either you're missing header information, or the HTML tags are not complete or broken. For example, you need the Content-Type statement with two newlines after.

If it works on CLI but now through CGI on the webserver, it has to be your code, a missing module in Apache, or something like that.