PERL Help (Re-Post)

SMN

SMN

Soldato
Joined
2 Nov 2008
Posts
2,502
Location
The ether
(Reposting, originally put it in the linux section by mistake!)

---------------------------------------------------------------

Hi All,
Anyone got skills with PERL? I'm trying to download a HTML file using PERL and the key thing is i need the transfer rate (Mbps/MBps) and the time taken to be displayed. I have the following which will print out the html page but does anyone have any input on how to get the speed/time to be output?

Also, i'm trying to do the same but for a file server, e.g. how long it takes to pull down a target file and the transfer speed.
Cheers all.

#!/usr/bin/perl

require HTTP::Request;
require LWP::UserAgent;

my $url = 'http://www.google.com';
my $request = HTTP::Request->new(GET => $url);
my $ua = LWP::UserAgent->new;
my $response = $ua->request($request);
$response->is_success or die $response->status_line;
my $content = $response->content;
print $content;
 
http://search.cpan.org/~lbrocard/WWW-Mechanize-Timed-0.44/lib/WWW/Mechanize/Timed.pm
Can time HTTP requests.
Pretty sure you can get the size from the HTTP headers, or just from the data received.

If you wanna do it without using a PM, can probably just get the time before you call GET and then again after it's called and record the difference.
Not sure which method would be more accurate.

(if you know time taken and size of page, you can calculate transfer rate speed = page size / time taken)
 
Nice one - you are a life saver!
Normally i'd work around wget but this has to work cross platform so PERL was what came to mind first.

Does anyone have any idea with the file request what the PERL "classes" are, e.g. the equivalent for HTTP::Request.
 
Problem using the 2nd post way, seems the WWW:Mechanize is throwing up errors:

an't locate WWW/Mechanize/Timed.pm in @Inc (@Inc contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./web-bench2.pl line 12.
BEGIN failed--compilation aborted at ./web-bench2.pl line 12.

Do i need to download anything extra for WWW:Mechanize to run (Sorry if its a dumb question!).
 
Back
Top Bottom