Perl CGI Hook 未按预期工作

发布于 2024-08-11 03:25:52 字数 2103 浏览 2 评论 0原文

我在使用 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 技术交流群。

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

发布评论

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

评论(1

生生漫 2024-08-18 03:25:52

我在打印到传递给钩子的文件句柄时遇到了一些困难,大概是因为缓冲问题。我决定使用 File::Slurp 中的 append_file 并传递日志文件的名称。

我还决定将脚本包装在 run 子文件中,以防万一您将其作为 mod_perl 下的注册表脚本运行。最后,我不知道times()函数从哪里来,所以我用time代替。这是脚本:

#!/usr/bin/perl

use strict; use warnings;

use CGI;
use File::Slurp;

run();

sub run {
    my $logfile = 'E:/srv/deploy/app/up.log';

    my $cgi = CGI->new(\&hook, $logfile);

    print $cgi->header('text/html'),
          $cgi->start_html,
          $cgi->p('Upload done'),
          $cgi->end_html;
    return;
}

sub hook {
    my ($filename, $buffer, $bytes_read, $logfile) = @_;
    append_file $logfile, \ sprintf("%d: %d\n", time, $bytes_read);
}

输出:

1258030571: 4051
1258030571: 8102
1258030571: 12153
...
1258030574: 5959021
1258030574: 5963072
1258030574: 5963469

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 from File::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 under mod_perl. Finally, I do not know where the times() function came from, so I used time instead. Here is the script:

#!/usr/bin/perl

use strict; use warnings;

use CGI;
use File::Slurp;

run();

sub run {
    my $logfile = 'E:/srv/deploy/app/up.log';

    my $cgi = CGI->new(\&hook, $logfile);

    print $cgi->header('text/html'),
          $cgi->start_html,
          $cgi->p('Upload done'),
          $cgi->end_html;
    return;
}

sub hook {
    my ($filename, $buffer, $bytes_read, $logfile) = @_;
    append_file $logfile, \ sprintf("%d: %d\n", time, $bytes_read);
}

Output:

1258030571: 4051
1258030571: 8102
1258030571: 12153
...
1258030574: 5959021
1258030574: 5963072
1258030574: 5963469

CGI version: 3.37
apache version: 2.2.4 (Windows)
perl version: 5.10.1 (ActiveState)

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