且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

的Perl CGI脚本根据运行返回不同的结果

更新时间:2023-01-24 14:54:23

是您的CGI脚本正在运行使用Apache的标准的CGI API或者你使用Apache ::注册mod_perl下运行它(或ModPerl ::注册处的Apache2) CGI模拟层?

我看到一个类似于你描述,它从mod_perl的的方式CGI模拟工作结果产生影响。细节这里讨论。

一个解决办法是采取申报的全局变量在与'我的'脚本的开始,改变关键字'我'为'我们'。

当然,你的问题可能是一些完全不同 - 这是很辛苦没有更多的信息说

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

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.