简体   繁体   English

使用file :: copy在mod_perl下提供图像失败

[英]Serving up images under mod_perl using file::copy fails

I have a CGI script that serves up images using the File::Copy CPAN module: 我有一个使用File :: Copy CPAN模块提供图像的CGI脚本:

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

This works fine under CGI but when run under mod_perl I get: 这在CGI下工作正常,但是在mod_perl下运行时,我得到:

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

I'm not sure if this is expected behaviour or if there's a bug somewhere. 我不确定这是预期的行为还是某处存在错误。 I'm new to mod_perl and find I am drowning in a sea of documentation at the moment. 我是mod_perl的新手,发现我现在淹没在大量文档中。 Is there any way to change my script so it runs fine under CGI or mod_perl without changes? 有什么办法可以更改我的脚本,使其在CGI或mod_perl下正常运行而无需更改?

From the mod_perl documentation 来自mod_perl文档

Under mod_perl, CORE::print( ) (using either STDOUT as a filehandle argument or no filehandle at all) will redirect output to Apache::print( ), since the STDOUT file handle is tied to Apache. 在mod_perl下,由于STDOUT文件句柄与Apache绑定,因此CORE :: print()(使用STDOUT作为文件句柄参数或根本不使用文件句柄)会将输出重定向到Apache :: print()。

And from the BUGS section if perltie 并从BUGS部分,如果perltie

Tied filehandles are still incomplete. 捆绑的文件句柄仍不完整。 sysopen(), truncate(), flock(), fcntl(), stat() and -X can't currently be trapped. sysopen(),truncate(),flock(),fcntl(),stat()和-X当前无法被捕获。

You can read more about this in the bug report at https://rt.perl.org/rt3//Public/Bug/Display.html?id=112164 if you wish. 如果您愿意,可以在错误报告中https://rt.perl.org/rt3//Public/Bug/Display.html?id=112164上阅读有关此内容的更多信息。

Not unless you're willing to change File::Copy or mod_perl (in negative ways). 除非您愿意更改File :: Copy或mod_perl(以负面方式),否则不可以。 File::Copy expects a file handle associated with a system file handle, but STDOUT is a tied file handle. File :: Copy需要与系统文件句柄关联的文件句柄,但STDOUT是绑定的文件句柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM