tags:

views:

59

answers:

2

Hi,

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

+1  A: 

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.

Grant McLean
Hmmmmmm. I may have some weird interconfict going on there related to the data the link describes. I'll disable mod_perl(it's just a plain CGI script) for a while and see if that works.
Paul Nathan
A: 

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.

Sierpinski