Perl CGI Hook 未按预期工作
我在使用 perl cgi 挂钩时遇到问题。
似乎在我按下“发送”按钮后,我的 perl 脚本不会立即调用,而是在文件完全上传后调用。
这可能是由于服务器设置造成的。
以前有人遇到过这个问题吗?
更新:
原因是预安装的:Apache 安全模块
感谢您的宝贵时间。
Perl 源代码
#!/usr/bin/perl -w
use CGI::Carp 'fatalsToBrowser';
use CGI qw(:cgi);
use IO::File;
use strict;
my $hook_file = "test.txt";
my $hook_handle = new IO::File;
$hook_handle->open(">> $hook_file") or die("Failed to open $hook_file: $!");
my $hook_query = CGI->new(\&hook, $hook_handle);
#start upload:
my $query = new CGI;
sub hook{
my ($current_filename, $buffer, $bytes_read, $hook_handle) = @_;
$hook_handle->print( join(" ",times()) . " -> " . $bytes_read ."\n" );
}
print "Content-type: text/html\n\n";
1;
为了监控上传进度,我使用 tail:
touch test.txt
tail -f test.txt
使用简单的 HTML POST 表单开始上传 5.5 MB 的文件。
输出总是相似的:
system time / user time / cpu time -> bytes transfered
0.03 0 0 0 -> 4037
...
...
...
0.11 0.01 0 0 -> 5520894
表示它在 0.1 秒内上传了 5.5 MB。
服务器配置
配置之间存在大量差异:
use Config qw(myconfig config_sh config_vars);
print myconfig();
print config_sh();
一些差异:(请告诉我其他内容是否有趣)
第一个值是工作服务器的值。
第二个值是 窃听 Dreamhost 服务器。
// dreamhost uses an older version of perl:
PERL_API_VERSION='10' -> '8'
api_versionstring='5.10.0' -> '5.8.0'
// dreamhost uses ByteLoader
extensions='B ...'
extensions='B ByteLoader ...'
// dreamhost uses an older gcc version
gccversion='4.3.3' -> '4.1.2 20061115 (prerelease) (Debian 4.1.1-21)'
// dreamhost uses an older libc version
gnulibc_version='2.9' -> '2.3.6'
// the dreamhost server is using fast stdio
usefaststdio='undef' -> 'define'
CGI(更新)
由于 Sinans 的建议,我更新了我的 CGI 版本(但是它没有解决我的问题)
// dreamhost cgi version
print $query->version (); -> 3.48
I have problems using the perl cgi hook.
It seems that after I pressed the "send" button my perl script is not called instandly but after the file is uploaded completely.
That might be because of a server setting.
Was anyone faced with this problem before?
Update:
The reason was the pre installed: Apache Security Module
Thanks for your time.
Perl Source Code
#!/usr/bin/perl -w
use CGI::Carp 'fatalsToBrowser';
use CGI qw(:cgi);
use IO::File;
use strict;
my $hook_file = "test.txt";
my $hook_handle = new IO::File;
$hook_handle->open(">> $hook_file") or die("Failed to open $hook_file: $!");
my $hook_query = CGI->new(\&hook, $hook_handle);
#start upload:
my $query = new CGI;
sub hook{
my ($current_filename, $buffer, $bytes_read, $hook_handle) = @_;
$hook_handle->print( join(" ",times()) . " -> " . $bytes_read ."\n" );
}
print "Content-type: text/html\n\n";
1;
To monitor the upload progress I am using tail:
touch test.txt
tail -f test.txt
Using a simple HTML POST form I start to upload a file of 5.5 MB.
The output is always similar:
system time / user time / cpu time -> bytes transfered
0.03 0 0 0 -> 4037
...
...
...
0.11 0.01 0 0 -> 5520894
Saying it uploaded 5.5 MB in 0.1 seconds.
Server configuration
There are tons of differences between the configurations:
use Config qw(myconfig config_sh config_vars);
print myconfig();
print config_sh();
Some differences: (please tell me if sth else could be interessting)
The first value is of the working server.
The second values is of the
bugging dreamhost server.
// dreamhost uses an older version of perl:
PERL_API_VERSION='10' -> '8'
api_versionstring='5.10.0' -> '5.8.0'
// dreamhost uses ByteLoader
extensions='B ...'
extensions='B ByteLoader ...'
// dreamhost uses an older gcc version
gccversion='4.3.3' -> '4.1.2 20061115 (prerelease) (Debian 4.1.1-21)'
// dreamhost uses an older libc version
gnulibc_version='2.9' -> '2.3.6'
// the dreamhost server is using fast stdio
usefaststdio='undef' -> 'define'
CGI (updated)
because of Sinans advice I updated my CGI version (however it did not solve my problem)
// dreamhost cgi version
print $query->version (); -> 3.48
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在打印到传递给钩子的文件句柄时遇到了一些困难,大概是因为缓冲问题。我决定使用
File::Slurp
中的append_file
并传递日志文件的名称。我还决定将脚本包装在
run
子文件中,以防万一您将其作为mod_perl
下的注册表脚本运行。最后,我不知道times()
函数从哪里来,所以我用time
代替。这是脚本:输出:
CGI 版本:3.37
阿帕奇版本:2.2.4(Windows)
perl 版本:5.10.1(ActiveState)
I had some difficulty with printing to a filehandle that is passed to the hook, presumably because of buffering issues. I decided to use
append_file
fromFile::Slurp
and passing the name of the log file.I also decided to wrap the script in a
run
sub just in case you are running this as a registry script undermod_perl
. Finally, I do not know where thetimes()
function came from, so I usedtime
instead. Here is the script:Output:
CGI version: 3.37
apache version: 2.2.4 (Windows)
perl version: 5.10.1 (ActiveState)