开发者

Perl CGI Hook is not working as expected

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;开发者_StackOverflow
$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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜