MR::AsyncHTTP - A zero-overhead Perl module for requesting HTTP in async manner, without event pools
use MR::AsyncHTTP; my $asynchttp = new MR::AsyncHTTP( connect_timeout=>0.6 ); # Send a request, dont wait answer right now my $req_id = $asynchttp->send_get( "http://example.com/" ); #..work with something else.. my $res = $asynchttp->check_response($req_id); if( !$res ) { # Not ready yet, work on something other } #..Finally, wait it. my $res = $asynchttp->wait($req_id); #..Send a couple of requests for(1..5) { $asynchttp->send_get( "http://example.com/request/".$_ ); } #Dedicate some time for sysread() to free buffers $asynchttp->poke; # Wait all responses $asynchttp->wait_all;
Note this module have limited functionality compared to say, LWP. Its designed to make simple requests async, thats all.
Captain: create a new object.
%opts can be:
Timeout for gethostbyname(). Default is 0.5 second. 0 to point no timeout.
Enable caching result of gethostbyname(). A false means no resolve cache. 'local' means object-scope cache. Other true values mean global cache between instances.
Default is 1 (global).
Set timeout for socket connect(). Default is 0.2 second. 0 to point no timeout.
Set timeout for response, not including connect. Affect wait() and wait_all() so they wont block like forever. Default is 1 second.
Send HTTP GET on given url. headers is a hash field=>value
Returns ID of request. Or undef on fail (sets $@ variable); 0 on timeout
Nonblocking check for response. Returns respnse hash when response is complete.
Wait for response upto response_timeout. Returns response hash or 0 if timeout.
Dedicate some time for sysread() to free system buffers.
Returns number of requests ready for processing in scalar context or list of ready ids in list context.
Blocking wait for all responses. Returns undef.
Limited functionality. Does not support nonstandard ports yet. Does not suport SSL yet.
Module massively rely on Time::HiRes::ualarm. So it uses ALRM signal. So do not wrap it with alarm() or ualarm().
Alt, <alt@cpan.org>
Copyright (C) 2012 by Alt
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.
To install MR::AsyncHTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MR::AsyncHTTP
CPAN shell
perl -MCPAN -e shell install MR::AsyncHTTP
For more information on module installation, please visit the detailed CPAN module installation guide.