Can perl be used to test ISP upload speed?

G

Guy

I suspect that this may not be in the proper newsgroup, and if so, please
ignore this posting.

I have perl 5.008 on a web server. I can create a perl script that can
manipulate data that is sent to it from an HTML form.

But I can't think of a way that perl could be used to test upload speed.

A good way to test upload speed would be to upload a file and calculate the
time it took to get there. But again I can't see how perl could be used to
test upload speed, and I'm wondering if it is possible.

I'm actually thinking that current online broadband speed tests use
something other that a server side script. I think they actually download a
small client side program?

Guy Doucet
 
G

Guy

I thought my previous postings already showed that :)

Actually, the only thing I -have- done with Perl, are CGI scripts running on
web servers, that manipulate data sent to it from forms inside HTML pages.
So I've really only seen where a few variables at a time are sent to a Perl
script and for that matter, the Perl script just updates text files and then
spits out HTML pages in return back to the browser.

The only thought that comes to mind for measuring upload speed is that I'd
have to keep track of time. Then making a few repeated calls to the Perl
script sending a little bit of data at a time. But making repeated calls
wouldn't be a good way either because each time a new channel has to be
created and this takes time not really related to upload speed. I also
don't know the inside of HTTP either. There must be a limit to the amount of
data an HTML document can send back to the web server - but that's another
issue.

Guy
 
G

Gunnar Hjalmarsson

[ Please do not top post! ]
I thought my previous postings already showed that :)

Well, sorry for my sulky reply. I just thought that your original post
was unnecessarily wordy. If I understand you right, you want to know:

"How can I have Perl measure the time it takes to run a certain
operation?"

Basically it can be done like this (assuming the operation takes a few
seconds):

my $starttime = time;
# code for accomplishing something
print 'Done. It took ', time - $starttime, " seconds.\n";
 
B

Ben Morrow

Gunnar Hjalmarsson said:
[ Please do not top post! ]
I thought my previous postings already showed that :)

Well, sorry for my sulky reply. I just thought that your original post
was unnecessarily wordy. If I understand you right, you want to know:

"How can I have Perl measure the time it takes to run a certain
operation?"

I would have said the OP would be better interpreted as "How can I
write a CGI that will time a file upload submitted to it?"; which I
don't *think* can be done...

Ben
 
G

Gunnar Hjalmarsson

Ben said:
I would have said the OP would be better interpreted as "How can I
write a CGI that will time a file upload submitted to it?"; which I
don't *think* can be done...

I can't see how a file upload would differ from other things in this
respect. This script appears to work fine for me:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $dir = '/path/to/incoming/directory';

my $starttime = time;

my $q = new CGI;
my $fh = $q->upload('myfile');
$q->uploadInfo($fh)->{'Content-Disposition'} =~
/filename="([\w\-\. ]+)"/;
my $name = ($1 or $starttime);
open FILE, "> $dir/$name" or die $!;
binmode FILE;
print FILE $_ while <$fh>;
close FILE;

print "Content-type: text/html\n\n";
print "$name was uploaded.<br>";
print "It took ", time - $starttime, " seconds.\n";

What am I missing?
 
B

Ben Morrow

Gunnar Hjalmarsson said:
I can't see how a file upload would differ from other things in this
respect. This script appears to work fine for me:
What am I missing?

*thinks*

Nothing. I was (not) thinking that the actual upload would be
completed before the CGI was invoked.

You may still end up with a smaller value for the time than you
should, if httpd starts buffering the upload before the perl script
starts.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top