#!/usr/bin/perl # Turn of auto flush for stdout $|=1; use HTTP::Async; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use strict; binmode STDOUT, ":utf8"; my $http_async = HTTP::Async->new( poll_interval => 0.05 ); my $url="http://www.bbc.co.uk/sport/0/"; # $url="http://www.google.com/"; print "Doing it 1st way\n"; my $ua=LWP::UserAgent->new; print time()." doing request\n"; my $resp=$ua->request( HTTP::Request->new( "GET", $url ) ); print time()." done\n"; print time()." DEBUG: Status is: ".$resp->status_line."\n"; print time()." LENGTH: ".length($resp->as_string)."\n"; print time()." Doing it 2nd way\n"; my $reqid = $http_async->add( HTTP::Request->new( "GET", $url ) ); print time()." NEWPOLL ADDED: $reqid\n"; while( 1 ) { # Check for any results if( $http_async->empty() ) { print time()." DEBUG: to_send=".$http_async->to_send_count." in_progress=".$http_async->in_progress_count." to_return=".$http_async->to_return_count." total=".$http_async->total_count."\n"; sleep(1); next; } print time()." DEBUG: Checking...\n"; my ( $resp, $reqid ) = $http_async->wait_for_next_response(1.0); if( !defined( $resp ) ) { next; } print time()." DEBUG: Got response reqid=$reqid\n"; print time()." DEBUG: Status is: ".$resp->status_line."\n"; print time()." LENGTH: ".length($resp->as_string)."\n"; last; }