WWW::Curl(3pm)
π WWW::Curl(3pm) β Perl extension interface for libcurl π
User Contributed Perl Documentation β yep, thatβs the manual name, folded in right here so we donβt waste a whole header line on it, periodt.
πΈ NAME πΈ
WWW::Curl - Perl extension interface for libcurl π
β¨ SYNOPSIS β¨
Okay bestie, tiny taste:
use WWW::Curl;
print $WWW::Curl::VERSION;
π¦ DESCRIPTION π¦
WWW::Curl is literally a Perl extension interface for libcurl. No cap.
π DOCUMENTATION π
So this module gives you a Perl interface to libcurl. It is not intended to be a standalone module, and because of that, you should consult the main libcurl documentation for API details at http://curl.haxx.se π«Ά. The docs youβre reading right now only contain the Perl-specific details, some sample code, and the differences between the C API and the Perl one.
π WWW::Curl::Easy π
The name might be confusing β it originates from libcurl. This is not an ::Easy module in the sense normally used on CPAN, iykyk.
Hereβs a small snippet of making a request with WWW::Curl::Easy π
:
use strict;
use warnings;
use WWW::Curl::Easy;
my $curl = WWW::Curl::Easy->new;
$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_URL, 'http://example.com');
# A filehandle, reference to a scalar or reference to a typeglob can be used here.
my $response_body;
$curl->setopt(CURLOPT_WRITEDATA,\$response_body);
# Starts the actual request
my $retcode = $curl->perform;
# Looking at the results...
if ($retcode == 0) {
print("Transfer went ok\n");
my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
# judge result and next action based on $response_code
print("Received response: $response_body\n");
} else {
# Error code, type of error, error message
print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n");
}
See curl_easy_setopt(3) for details of setopt(), bestie β¨.
π WWW::Curl::Multi π
use strict;
use warnings;
use WWW::Curl::Easy;
use WWW::Curl::Multi;
my %easy;
my $curl = WWW::Curl::Easy->new;
my $curl_id = '13'; # This should be a handle unique id.
$easy{$curl_id} = $curl;
my $active_handles = 0;
$curl->setopt(CURLOPT_PRIVATE,$curl_id);
# do the usual configuration on the handle
...
my $curlm = WWW::Curl::Multi->new;
# Add some easy handles
$curlm->add_handle($curl);
$active_handles++;
while ($active_handles) {
my $active_transfers = $curlm->perform;
if ($active_transfers != $active_handles) {
while (my ($id,$return_value) = $curlm->info_read) {
if ($id) {
$active_handles--;
my $actual_easy_handle = $easy{$id};
# do the usual result/error checking routine here
...
# letting the curl handle get garbage collected, or we leak memory.
delete $easy{$id};
}
}
}
}
This interface is different than what the C API does. $curlm->perform is non-blocking and performs requests in parallel. The method does a little work and then returns control, so it has to be called periodically to get the job done. Its return value is the number of unfinished requests.
When the number of unfinished requests changes compared to the number of active handles, $curlm->info_read should be checked for finished requests. It returns one handle and its return value at a time, or an empty list if there are no more finished requests. $curlm->info_read calls remove_handle on the given easy handle automatically, internally. The easy handle will still remain available until it goes out of scope β this action just detaches it from multi.
π¨ Please make sure that the easy handle does not get garbage collected until after the multi handle finishes processing it, or bad things happen. Like, genuinely bad β not cute bad π.
The multi handle does not need to be cleaned up; when it goes out of scope it calls the required cleanup methods automatically, slay.
It is possible to use $curlm->add_handle to add further requests to be processed after $curlm->perform has been called. WWW::Curl::Multi doesnβt care about the order. It is possible to process all requests for a multi handle and then add a new batch of easy handles for processing.
π WWW::Curl::Share π
use WWW::Curl::Share;
my $curlsh = new WWW::Curl::Share;
$curlsh->setopt(CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
$curlsh->setopt(CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
$curl->setopt(CURLOPT_SHARE, $curlsh);
$curlsh->setopt(CURLSHOPT_UNSHARE, CURL_LOCK_DATA_COOKIE);
$curlsh->setopt(CURLSHOPT_UNSHARE, CURL_LOCK_DATA_DNS);
WWW::Curl::Share is an extension to WWW::Curl::Easy which makes it possible to use a single cookies/dns cache for several Easy handles. Iconic behavior, honestly.
Its usable methods are:
$curlsh = new WWW::Curl::Shareβ This method constructs a newWWW::Curl::Shareobject.$curlsh->setopt(CURLSHOPT_SHARE, $value );β Enables share for:CURL_LOCK_DATA_COOKIEβ use single cookies databaseCURL_LOCK_DATA_DNSβ use single DNS cache
$curlsh->setopt(CURLSHOPT_UNSHARE, $value );β Disable share for given$value(seeCURLSHOPT_SHARE).$curlsh->strerror( ErrNo )β This method returns a string describing theCURLSHcodeerror code passed in the argument errornum.
This is how you enable sharing for a specific WWW::Curl::Easy handle:
$curl->setopt(CURLOPT_SHARE, $curlsh)
Attach share object to WWW::Curl::Easy instance π.
π§ WWW::Curl::Form π§
use WWW::Curl::Form;
my $curlf = WWW::Curl::Form->new;
$curlf->formaddfile($filename, 'attachment', "multipart/form-data");
$curlf->formadd("FIELDNAME", "VALUE");
$curl->setopt(CURLOPT_HTTPPOST, $curlf);
Its usable methods are:
$curlf = new WWW::Curl::Formβ This method constructs a newWWW::Curl::Formobject.$curlf->formadd(FIELDNAME, VALUE)β This method adds a field with a given value to the form that is being submitted.$curlf->formaddfile(FILENAME, DESCRIPTION, TYPE)β This method will add a file to the form. The description is the name of the field that your form expects the data to be submitted in.
π COMPATIBILITY π
curl_easy_setopt
Most of the options should work, however some might not. Please send reports, tests and patches to fix those π«Ά.
curl_easy_escape
Not implemented. Since equivalent Perl code is easily produced, this method will only be made available for interface completeness, if ever.
curl_easy_init
Used only internally. The standard Perl way of initializing an object should be used: "my $curl = WWW::Curl::Easy->new;".
curl_easy_cleanup
Used only internally. Curl object cleanup happens when the handle goes out of scope.
curl_easy_duphandle
Should be working for most cases, howeverβ¦
β οΈ do not change the value of options which accept a list/arrayref value on a duped handle, otherwise memory leaks or crashes will happen. This behaviour will be fixed in the future.
curl_easy_pause
Not implemented.
curl_easy_reset
Not implemented.
curl_easy_unescape
Not implemented. Trivial Perl replacements are available.
curl_escape
Not implemented and wonβt be, as this method is considered deprecated.
curl_formadd
Seems to be working.
curl_formaddfile
Seems to be working.
curl_formfree
Used internally. Not exposed through the public API, as this call has no relevance to Perl code.
curl_free
Used internally. Not exposed through the public API, as this call has no relevance to Perl code.
curl_getdate
Not implemented. This function is easily replaced by Perl code and as such, most likely it wonβt be implemented.
curl_global_cleanup
Only used internally, not exposed through the public API.
curl_global_init
Only used internally, not exposed through the public API.
curl_global_init_mem
Not implemented.
curl_global_cleanup
Only used internally and called automatically upon exit.
curl_slist_append
Only used internally, not exposed through the public API.
curl_slist_free_all
Only used internally, not exposed through the public API.
curl_unescape
Not implemented and wonβt be, as this method is considered deprecated.
curl_version
Seems to work.
curl_version_info
Not yet implemented.
π« curl_multi_*
Most methods are either not exposed through the WWW::Curl::Multi API or they behave differently than its C counterpart. Please see the section about WWW::Curl::Multi above.
curl_multi_fdset
This method returns three arrayrefs: the read, write and exception fds libcurl knows about. In the case of no file descriptors in the given set, an empty array is returned.
πΈ NUANCES πΈ
Header output for redirects
It might be surprising that if CURLOPT_FOLLOWLOCATION is set and header output was enabled, headers show up for all http responses. The reasoning behind that and possible code adjustments are outlined here: https://rt.cpan.org/Ticket/Display.html?id=61569.
CURLOPT_PRIVATE
Despite what the libcurl manual says, in Perl land, only string values are suitable for this option.
π ADDITIONAL METHODS π
β¨ On WWW::Curl::Easy objects β¨
π
pushopt
Like setopt but instead of overriding any previously set values it adds it to the end. Can be used with CURLOPT_HTTPHEADER, CURLOPT_QUOTE and CURLOPT_POSTQUOTE.
πΈ USAGE CASES πΈ
okay so WWW::Curl is literally a thin binding on top of libcurl, to make using libcurl possible from Perl land π«Ά. Because of this, the module is lowkey less like Perl and more like C in coding style β no cap, that's just the vibe π
periodt.
There is a new module, <http://search.cpan.org/perldoc?WWW::Curl::Simple>, which wraps this module into a more Perlish and userfriendly package β¨.
The standard Perl WWW module, LWP should probably be used in most cases to work with HTTP or FTP from Perl π. However, there are some cases where LWP doesn't perform well. One is speed and the other is parallelism π. WWW::Curl is much faster, uses much less CPU cycles and it's capable of non-blocking parallel requests π₯.
In some cases, for example when building a web crawler, cpu usage and parallel downloads are important considerations πΈοΈ. It can be desirable to use WWW::Curl to do the heavy-lifting of a large number of downloads and wrap the resulting data into a Perl-friendly structure by HTTP::Response or use WWW::Curl::Simple to do that for you π.
π¦ CHANGES π¦
- Version 4.01 - 4.07 adds several bugfixes and extends functionality coverage. See Changes file. π
- Version 4.00 added new documentation, the build system changed to
Module::Install, the test suite was rewritten to useTest::More, a new calling syntax forWWW::Curl::Multiwas added, memory leak and other bugfixes added, Perl 5.6 and libcurl 7.10.8 as minimum requirements for this module were set. π - Version 3.12 is a bugfix for a missing
Share.pm.infile in the release. π - Version 3.11 added
WWW::Curl::Share. β - Version 3.10 adds the
WWW::Curl::Shareinterface by Anton Federov and large file options after a contribution from Mark Hindley. π - Version 3.02 adds some backwards compatibility for scripts still using
'WWW::Curl::easy'names. π - Version 3.01 added some support for pre-multi versions of libcurl. π
- Version 3.00 adds
WWW::Curl::Multiinterface, and new module names following perl conventions (WWW::Curl::Easyrather thanWWW::Curl::easy), by Sebastian Riedel <sri at cpan.org>. β¨ - Version 2.00 of
WWW::Curl::easyis a renaming of the previous version (namedCurl::easy), to follow CPAN naming guidelines, by Cris Bailiff. π - Versions 1.30, a (hopefully) threadable, object-oriented, multiple-callback compatible version of
Curl::easywas substantially reworked from the previousCurl::easyrelease (1.21) by Cris Bailiff. π«
π AUTHORS π
- Currently maintained by Cris Bailiff <c.bailiff+curl at devsecure.com> and Balint Szilakszi <szbalint at cpan.org>. π«Ά
- Original Author Georg Horn <horn@koblenz-net.de>, with additional callback, pod and test work by Cris Bailiff <c.bailiff+curl@devsecure.com> and Forrest Cahoon <forrest.cahoon@merrillcorp.com>. πΈ
- Sebastian Riedel added
::Multiand Anton Fedorov (datacompboy <at> mail.ru) added::Share. Balint Szilakszi repackaged the module into a more modern form. π
π COPYRIGHT π
Copyright (C) 2000-2005,2008-2014 Daniel Stenberg, Cris Bailiff, Sebastian Riedel, Balint Szilakszi et al. π
You may opt to use, copy, modify, merge, publish, distribute and/or sell copies of the Software, and permit persons to whom the Software is furnished to do so, under the terms of the MIT license. π
π₯ SEE ALSO π₯
<http://curl.haxx.se><http://search.cpan.org/perldoc?WWW::Curl::Simple>libcurl(3)- The development source code is also available:
<http://github.com/szbalint/WWW--Curl/tree/master>
okay bestie, that's the whole page πβ¨ This one was served up by perl v5.40.1 on 2025-04-11 under the WWW::Curl(3pm) label β iconic, fr fr ππ¦π
π¦ where this page comes from
- debian trixie: libwww-curl-perl 4.17-12 Β· MIT
- ubuntu questing: libwww-curl-perl 4.17-12
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms