HTTP-GHTTP

 view release on metacpan or  search on metacpan

GHTTP.pm  view on Meta::CPAN

the remote URI. Optionally pass in headers.

=head1 ASYNC OPERATION

Its possible to use an asynchronous mode of operation with ghttp. Here's
a brief example of how:

    my $r = HTTP::GHTTP->new("http://axkit.org/");
    $r->set_async; 
    $r->set_chunksize(1);
    $r->prepare;

    my $status;
    while ($status = $r->process) {
        # do something
        # you can do $r->get_body in here if you want to
        # but it always returns the entire body.
    }
    
    die "An error occured" unless defined $status;
    
    print $r->get_body;

Doing timeouts is an exercise for the reader (hint: lookup select() in
perlfunc).

Note also that $sock above is an IO::Handle, not an IO::Socket, although
you can probably get away with re-blessing it. Also note that by calling
$r->get_socket() you load IO::Handle, which probably brings a lot of
code with it, thereby obliterating a lot of the use for libghttp. So
use at your own risk :-)

=head1 AUTHOR

Matt Sergeant, matt@sergeant.org

=head1 LICENSE

This is free software, you may use it and distribute it under the 
same terms as Perl itself. Please be aware though that libghttp is
licensed under the terms of the LGPL, a copy of which can be found
in the libghttp distribution.

=head1 BUGS

Probably many - this is my first adventure into XS.

libghttp doesn't support SSL. When libghttp does support SSL, so will
HTTP::GHTTP. The author of libghttp, Chris Blizzard <blizzard@redhat.com>
is looking for patches to support SSL, so get coding!

=head1 BENCHMARKS

Benchmarking this sort of thing is often difficult, and I don't want
to offend anyone. But as well as being lightweight (HTTP::GHTTP is
about 4 times less code than either LWP::UserAgent, or HTTP::Lite), it
is also in my tests significantly faster. Here are my benchmark
results requesting http://localhost/ (the Apache "Successful Install"
page):

    Benchmark: timing 1000 iterations of ghttp, lite, lwp...
         ghttp:  8 wallclock secs ( 0.96 usr +  1.16 sys =  2.12 CPU)
          lite: 21 wallclock secs ( 3.00 usr +  3.44 sys =  6.44 CPU)
           lwp: 18 wallclock secs ( 9.76 usr +  1.59 sys = 11.35 CPU)

=cut



( run in 1.861 second using v1.01-cache-2.11-cpan-71847e10f99 )