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

发布于 2024-09-08 01:12:31 字数 371 浏览 2 评论 0原文

我有一个 Perl CGI 脚本,它明显随机地发出不同的 HTML。所有输入都没有改变。例如,我将运行 wget 两次并得到两个不同的结果。 CGI 由开发数据库支持,该数据库也不会改变。

我有一个调试语句,通知我相同数量的元素从数据库返回到脚本中。

坦白说,我很困惑。逻辑、DB 和输入不会改变,但输出会改变。

Ubuntu 10.04 上的 http 服务器是 apache2。 Perl 版本是 perl 5.10。

编辑:每当我从服务器上的命令行运行它时,输出都是正确的。

edit2:一些糟糕的运行看起来像是脚本的先前版本。我不认为 Apache 会缓存 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....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

远昼 2024-09-15 01:12:31

您的 CGI 脚本是使用 Apache 的标准 CGI API 运行,还是使用 Apache::Registry(或 Apache2 中的 ModPerl::Registry)CGI 模拟层在 mod_perl 下运行?

我看到了与您所描述的类似的效果,这是由 mod_perl 的 CGI 模拟工作方式产生的。详细信息此处讨论

一种解决方法是采用在脚本开头用“my”声明的任何“全局”变量,并将关键字“my”更改为“our”。

当然,您的问题可能完全不同 - 如果没有更多信息,很难说。

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.

℉服软 2024-09-15 01:12:31

缓存:Apache 可能不会缓存,但您的浏览器可能会缓存。关闭缓存(将浏览器缓存设置为 0MB)。

命令行:如果您的输出从网页到 CLI 执行的脚本不同,那么您可能缺少标头信息,或者 HTML 标记不完整或损坏。例如,您需要 Content-Type 语句后带有两个换行符。

如果它在 CLI 上工作,但现在通过 Web 服务器上的 CGI 工作,那么它必须是您的代码、Apache 中缺少的模块或类似的东西。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文