Click to See Complete Forum and Search --> : Perl script faster in FF than IE!?


Geat
11-13-2008, 04:01 AM
I have a very frustrating issue with a perl script which I hope someone has identified before.

The Perl script accepts a file upload from a standard HTML form, and correctly isolates the file from the post data and writes it to disk.

After the file has been assembled, it renders a HTML form that contains some information about the file, which is auto-submitted via Javscript.

In Firefox, the page with the form is displayed for about a second before it redirects. However, in IE (6 and 7) it stays on the page for about a minute (with IE indicating it is loading, not just sitting there waiting for the JS) before finally moving on to the next page.

Does anybody know what this could be? I assumed that IE was posting some superfluous data in the form, hence the delay, but I outputted all of the POST data/headers and nothing looked untoward.

Any help would be greatly appreciated!

scragar
11-13-2008, 04:35 AM
I know IE7 has a bit of a bug with uploading, where it split's files into chunks that are too large, then has to split those chunks into 2 in order to send the packets(adding about 30-40% to the size of the upload(which is not normally noticed on small files)), but I have never heard of such a large time differences.

Might be intresting to run a test, to see when IE decides it's done, and when the server reports success, might be a difference worth looking at.

Geat
11-13-2008, 04:39 AM
Thanks for the reply. The actual upload takes the same amount of time in both browsers, as the form which is automatically submitted is only rendered once the upload has finished. It's this second form, which simply sends a few text fields, that takes a varying amount of time to submit. Given the nature of the form, it makes no sense!

Jeff Mott
11-13-2008, 08:37 AM
You'll need to show us the code and the live page, otherwise all we can do is guess.

Geat
11-13-2008, 08:47 AM
I'll say again that this works absolutely fine in Firefox, and in Google Chrome, but in Internet Explorer the HTML at the bottom is rendered some 50 seconds before the next page is reached.

I can't show you the page as it's all part of our login area, but here's the code:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

#SETTINGS
$tmpDir = "/mydirectory";
$maxFileSize = 52428800; #50Mb

$dataFile = "";
$settingsFile = "";

$len = $ENV{'CONTENT_LENGTH'};

$bRead = 0;

$state="";

if($len > $maxFileSize) {
$state="2"; #state 2 for the size error
goto error;
}

@qstring=split(/&/,$ENV{'QUERY_STRING'});
@p1 = split(/=/,$qstring[0]);
@p12 = split(/=/,$qstring[1]);
$sessionID = $p1[1];
$userID = $p12[1];

$dataFile = $sessionID."_data";
$finalFile = $sessionID."_data_video";
$settingsFile = $sessionID."_set";

open SIZE,">".$tmpDir.$settingsFile;
binmode SIZE;
print SIZE $len;
close SIZE;

binmode STDIN;

open FILE,">".$tmpDir.$dataFile;
binmode FILE;

while (read (STDIN ,$LINE, 4096) && $bRead < $len ) {
$bRead += length $LINE;

print FILE $LINE;
}

close (FILE);

$sizeTmpFile = (-s $tmpDir.$dataFile);

if($sizeTmpFile == $len) {
open FILE,$tmpDir.$dataFile;
binmode FILE;
read FILE,$data,$len;

@part = split /-----------------------------.{9}/, $data;
@part2 = split /\n/, $part[1], 5;

$originalNameTmp1 = $part2[1];
@originalNameTmp2 = split /;/,$originalNameTmp1;
@originalNameTmp3 = split /=/,$originalNameTmp2[2];
$originalName=$originalNameTmp3[1];
chop($originalName);
chop($originalName);
$originalName = substr($originalName,1);

$endFile = $part2[4];

chop($endFile);
chop($endFile);

close (FILE);


open FILE, ">".$tmpDir.$finalFile;
binmode FILE;
print FILE $endFile;
close FILE;

$state="1";
}
else {
$state="3";
}

unlink($tmpDir.$dataFile);
unlink($tmpDir.$settingsFile);

local (*in) = @_ if @_;
local ($i, $loc, $key, $val);

$WinNT = 0;

if($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)
{
$Boundary = '--'.$1;
@list = split(/$Boundary/, $data);
$HeaderBody = $list[1];
$HeaderBody =~ /\r\n\r\n|\n\n/;
$Header = $`;
$Body = $';
$Body =~ s/\r\n$//;
$in{'filedata'} = $Body;
$Header =~ /filename=\"(.+)\"/;
$in{'f'} = $1;
$in{'f'} =~ s/\"//g;
$in{'f'} =~ s/\s//g;

for($i=2; $list[$i]; $i++)
{
$list[$i] =~ s/^.+name=$//;
$list[$i] =~ /\"(\w+)\"/;
$key = $1;
$val = $';
$val =~ s/(^(\r\n\r\n|\n\n))|(\r\n$|\n$)//g;
$val =~ s/%(..)/pack("c", hex($1))/ge;
$in{$key} = $val;
}
}


error:

print <<ENDFILE;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<p style="margin-top:15px;font-family:Arial;text-align:center;">Preparing Conversion, Please Wait...</p>

<script language="javascript">
location.href='URL_OF_NEXT_PAGE';
</script>

</body>
</html>
ENDFILE

Jeff Mott
11-13-2008, 09:02 AM
Well, it doesn't look like the HTML should hang the browser, and it doesn't look like the Perl script should hang the server.

All I can suggest, and this is a longshot for solving your problem, is to scrap the self-made file upload processing code and use the CGI module instead. See the docs (http://perldoc.perl.org/CGI.html#CREATING-A-FILE-UPLOAD-FIELD) for more info.

But even though this is a longshot, the plus side is that this is something you should be doing anyway.

Geat
11-13-2008, 11:28 AM
Thanks for the suggestion - I tried out CGI and it "worked" in the same way as the existing code, but didn't solve the Internet Explorer problem.

The reason I'm using Perl for this one little section is because I have a progress meter for the upload - everything else is PHP. The file finishes uploading (according to the meter), then the output of the perl file is displayed. This says to me that all processing is done, as the HTML output is at the end. However, IE still seems to be sending data (or otherwise communicating) for this extra minute or so, before finally reaching the next page.

debiguana
12-11-2008, 01:24 AM
You might look at using jClientUpload. While it is java-based (which isn't a problem much these days), and costs $30, the cost is very much worth it. I've used it on several projects where I needed to provide the progress-bar functionality (or very-large-file upload functionality) quite successfully.

One of the best features about it is that you can configure it to kick off an appropriate file-processing script *and* redirect the browser to a completion page, which is very handy.

[Edit: jClient URL: http://www.javazoom.net/applets/jclientupload/jclientupload.html]