【问题标题】:Serving up images under mod_perl using file::copy fails使用 file::copy 在 mod_perl 下提供图像失败
【发布时间】:2012-10-13 20:05:28
【问题描述】:

我有一个 CGI 脚本,它使用 File::Copy CPAN 模块提供图像:

use File::Copy;
.... (set appropriate content header)
binmode STDOUT;
copy $imageFile, \*STDOUT || die "Image delivery failed: $!";

这在 CGI 下工作正常,但在 mod_perl 下运行时我得到:

[File::Copy::copy 140]  stat() on unopened filehandle STDOUT at /usr/share/perl/5.14/File/Copy.pm line 140.

我不确定这是预期行为还是某处存在错误。我是 mod_perl 的新手,发现我现在正淹没在文档的海洋中。有什么方法可以更改我的脚本,使其在 CGI 或 mod_perl 下运行良好而无需更改?

【问题讨论】:

    标签: perl cgi mod-perl mod-perl2


    【解决方案1】:

    来自 mod_perl 文档

    在 mod_perl 下,CORE::print( )(使用 STDOUT 作为文件句柄参数或根本不使用文件句柄)会将输出重定向到 Apache::print( ),因为 STDOUT 文件句柄与 Apache 绑定。

    如果 perltie 来自 BUGS 部分

    绑定的文件句柄仍然不完整。目前无法捕获 sysopen()、truncate()、flock()、fcntl()、stat() 和 -X。

    如果您愿意,可以在https://rt.perl.org/rt3//Public/Bug/Display.html?id=112164 的错误报告中阅读更多相关信息。

    【讨论】:

      【解决方案2】:

      除非您愿意更改 File::Copy 或 mod_perl(以消极方式),否则不会。 File::Copy 需要一个与系统文件句柄关联的文件句柄,但 STDOUT 是一个绑定的文件句柄。

      【讨论】:

        猜你喜欢
        • 2014-10-13
        • 1970-01-01
        • 1970-01-01
        • 2016-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-13
        • 2019-10-14
        相关资源
        最近更新 更多