.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "WWW::Curl 3pm" .TH WWW::Curl 3pm "2020-11-08" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" WWW::Curl \- Perl extension interface for libcurl .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use WWW::Curl; \& print $WWW::Curl::VERSION; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" WWW::Curl is a Perl extension interface for libcurl. .SH "DOCUMENTATION" .IX Header "DOCUMENTATION" This module provides a Perl interface to libcurl. It is not intended to be a standalone module and because of this, the main libcurl documentation should be consulted for \s-1API\s0 details at . The documentation you're reading right now only contains the Perl specific details, some sample code and the differences between the C \s-1API\s0 and the Perl one. .SH "WWW::Curl::Easy" .IX Header "WWW::Curl::Easy" The name might be confusing, it originates from libcurl. This is not an ::Easy module in the sense normally used on \s-1CPAN.\s0 .PP Here is a small snippet of making a request with WWW::Curl::Easy. .PP .Vb 3 \& use strict; \& use warnings; \& use WWW::Curl::Easy; \& \& my $curl = WWW::Curl::Easy\->new; \& \& $curl\->setopt(CURLOPT_HEADER,1); \& $curl\->setopt(CURLOPT_URL, \*(Aqhttp://example.com\*(Aq); \& \& # A filehandle, reference to a scalar or reference to a typeglob can be used here. \& my $response_body; \& $curl\->setopt(CURLOPT_WRITEDATA,\e$response_body); \& \& # Starts the actual request \& my $retcode = $curl\->perform; \& \& # Looking at the results... \& if ($retcode == 0) { \& print("Transfer went ok\en"); \& my $response_code = $curl\->getinfo(CURLINFO_HTTP_CODE); \& # judge result and next action based on $response_code \& print("Received response: $response_body\en"); \& } else { \& # Error code, type of error, error message \& print("An error happened: $retcode ".$curl\->strerror($retcode)." ".$curl\->errbuf."\en"); \& } .Ve .PP See \fBcurl_easy_setopt\fR\|(3) for details of \f(CW\*(C`setopt()\*(C'\fR. .SH "WWW::Curl::Multi" .IX Header "WWW::Curl::Multi" .Vb 4 \& use strict; \& use warnings; \& use WWW::Curl::Easy; \& use WWW::Curl::Multi; \& \& my %easy; \& my $curl = WWW::Curl::Easy\->new; \& my $curl_id = \*(Aq13\*(Aq; # 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}; \& } \& } \& } \& } .Ve .PP This interface is different than what the C \s-1API\s0 does. \f(CW$curlm\fR\->perform is non-blocking and performs requests in parallel. The method does a little work and then returns control, therefor it has to be called periodically to get the job done. It's return value is the number of unfinished requests. .PP When the number of unfinished requests changes compared to the number of active handles, \f(CW$curlm\fR\->info_read should be checked for finished requests. It returns one handle and it's return value at a time, or an empty list if there are no more finished requests. \f(CW$curlm\fR\->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. .PP Please make sure that the easy handle does not get garbage collected until after the multi handle finishes processing it, or bad things happen. .PP The multi handle does not need to be cleaned up, when it goes out of scope it calls the required cleanup methods automatically. .PP It is possible to use \f(CW$curlm\fR\->add_handle to add further requests to be processed after \f(CW$curlm\fR\->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. .SH "WWW::Curl::Share" .IX Header "WWW::Curl::Share" .Vb 7 \& 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); .Ve .PP 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. .PP It's usable methods are: .PP .Vb 2 \& $curlsh = new WWW::Curl::Share \& This method constructs a new WWW::Curl::Share object. \& \& $curlsh\->setopt(CURLSHOPT_SHARE, $value ); \& Enables share for: \& CURL_LOCK_DATA_COOKIE use single cookies database \& CURL_LOCK_DATA_DNS use single DNS cache \& $curlsh\->setopt(CURLSHOPT_UNSHARE, $value ); \& Disable share for given $value (see CURLSHOPT_SHARE) \& \& $curlsh\->strerror( ErrNo ) \& This method returns a string describing the CURLSHcode error \& code passed in the argument errornum. .Ve .PP This is how you enable sharing for a specific WWW::Curl::Easy handle: .PP .Vb 2 \& $curl\->setopt(CURLOPT_SHARE, $curlsh) \& Attach share object to WWW::Curl::Easy instance .Ve .SH "WWW::Curl::Form" .IX Header "WWW::Curl::Form" .Vb 4 \& use WWW::Curl::Form; \& my $curlf = WWW::Curl::Form\->new; \& $curlf\->formaddfile($filename, \*(Aqattachment\*(Aq, "multipart/form\-data"); \& $curlf\->formadd("FIELDNAME", "VALUE"); \& \& $curl\->setopt(CURLOPT_HTTPPOST, $curlf); .Ve .PP Its usable methods are: .PP .Vb 2 \& $curlf = new WWW::Curl::Form \& This method constructs a new WWW::Curl::Form object. \& \& $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 you form expects the data to be submitted in. .Ve .SH "COMPATIBILITY" .IX Header "COMPATIBILITY" .IP "curl_easy_setopt" 4 .IX Item "curl_easy_setopt" Most of the options should work, however some might not. Please send reports, tests and patches to fix those. .IP "curl_easy_escape" 4 .IX Item "curl_easy_escape" Not implemented. Since equivalent Perl code is easily produced, this method will only made available for interface completeness, if ever. .IP "curl_easy_init" 4 .IX Item "curl_easy_init" Used only internally. The standard Perl way of initializing an object should be used, \f(CW\*(C`my $curl = WWW::Curl::Easy\->new;\*(C'\fR. .IP "curl_easy_cleanup" 4 .IX Item "curl_easy_cleanup" Used only internally. Curl object cleanup happens when the handle goes out of scope. .IP "curl_easy_duphandle" 4 .IX Item "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. .IP "curl_easy_pause" 4 .IX Item "curl_easy_pause" Not implemented. .IP "curl_easy_reset" 4 .IX Item "curl_easy_reset" Not implemented. .IP "curl_easy_unescape" 4 .IX Item "curl_easy_unescape" Not implemented. Trivial Perl replacements are available. .IP "curl_escape" 4 .IX Item "curl_escape" Not implemented and won't be as this method is considered deprecated. .IP "curl_formadd" 4 .IX Item "curl_formadd" Seems to be working. .IP "curl_formaddfile" 4 .IX Item "curl_formaddfile" Seems to be working. .IP "curl_formfree" 4 .IX Item "curl_formfree" Used internally. Not exposed through the public \s-1API,\s0 as this call has no relevance to Perl code. .IP "curl_free" 4 .IX Item "curl_free" Used internally. Not exposed through the public \s-1API,\s0 as this call has no relevance to Perl code. .IP "curl_getdate" 4 .IX Item "curl_getdate" Not implemented. This function is easily replaced by Perl code and as such, most likely it won't be implemented. .IP "curl_global_cleanup" 4 .IX Item "curl_global_cleanup" Only used internally, not exposed through the public \s-1API.\s0 .IP "curl_global_init" 4 .IX Item "curl_global_init" Only used internally, not exposed through the public \s-1API.\s0 .IP "curl_global_init_mem" 4 .IX Item "curl_global_init_mem" Not implemented. .IP "curl_global_cleanup" 4 .IX Item "curl_global_cleanup" Only used internally and called automatically upon exit. .IP "curl_slist_append" 4 .IX Item "curl_slist_append" Only used internally, not exposed through the public \s-1API.\s0 .IP "curl_slist_free_all" 4 .IX Item "curl_slist_free_all" Only used internally, not exposed through the public \s-1API.\s0 .IP "curl_unescape" 4 .IX Item "curl_unescape" Not implemented and won't be, as this method is considered deprecated. .IP "curl_version" 4 .IX Item "curl_version" Seems to work. .IP "curl_version_info" 4 .IX Item "curl_version_info" Not yet implemented. .IP "curl_multi_*" 4 .IX Item "curl_multi_*" Most methods are either not exposed through the WWW::Curl::Multi \s-1API\s0 or they behave differently than it's C counterpart. Please see the section about WWW::Curl::Multi above. .IP "curl_multi_fdset" 4 .IX Item "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. .SH "NUANCES" .IX Header "NUANCES" .SS "Header output for redirects" .IX Subsection "Header output for redirects" It might be surprising that if \f(CW\*(C`CURLOPT_FOLLOWLOCATION\*(C'\fR 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: . .SS "\s-1CURLOPT_PRIVATE\s0" .IX Subsection "CURLOPT_PRIVATE" Despite what the libcurl manual says, in Perl land, only string values are suitable for this option. .SH "ADDITIONAL METHODS" .IX Header "ADDITIONAL METHODS" .SS "On WWW::Curl::Easy objects" .IX Subsection "On WWW::Curl::Easy objects" .IP "pushopt" 4 .IX Item "pushopt" Like \f(CW\*(C`setopt\*(C'\fR but instead of overriding any previously set values it adds it to the end. Can be used with \f(CW\*(C`CURLOPT_HTTPHEADER\*(C'\fR, \f(CW\*(C`CURLOPT_QUOTE\*(C'\fR and \&\f(CW\*(C`CURLOPT_POSTQUOTE\*(C'\fR. .SH "USAGE CASES" .IX Header "USAGE CASES" WWW::Curl is a thin binding on top of libcurl, to make using libcurl possible from Perl land. Because of this, the module is less like Perl and more like C in coding style. .PP There is a new module, , which wraps this module into a more Perlish and userfriendly package. .PP The standard Perl \s-1WWW\s0 module, \s-1LWP\s0 should probably be used in most cases to work with \s-1HTTP\s0 or \s-1FTP\s0 from Perl. However, there are some cases where \s-1LWP\s0 doesn't perform well. One is speed and the other is parallelism. WWW::Curl is much faster, uses much less \s-1CPU\s0 cycles and it's capable of non-blocking parallel requests. .PP 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. .SH "CHANGES" .IX Header "CHANGES" Version 4.01 \- 4.07 adds several bugfixes and extends functionality coverage. See Changes file. .PP Version 4.00 added new documentation, the build system changed to Module::Install, the test suite was rewritten to use Test::More, a new calling syntax for WWW::Curl::Multi was added, memory leak and other bugfixes added, Perl 5.6 and libcurl 7.10.8 as minimum requirements for this module were set. .PP Version 3.12 is a bugfix for a missing Share.pm.in file in the release. .PP Version 3.11 added WWW::Curl::Share. .PP Version 3.10 adds the WWW::Curl::Share interface by Anton Federov and large file options after a contribution from Mark Hindley. .PP Version 3.02 adds some backwards compatibility for scripts still using \&'WWW::Curl::easy' names. .PP Version 3.01 added some support for pre-multi versions of libcurl. .PP Version 3.00 adds WWW::Curl::Multi interface, and new module names following perl conventions (WWW::Curl::Easy rather than WWW::Curl::easy), by Sebastian Riedel . .PP Version 2.00 of WWW::Curl::easy is a renaming of the previous version (named Curl::easy), to follow \s-1CPAN\s0 naming guidelines, by Cris Bailiff. .PP Versions 1.30, a (hopefully) threadable, object-oriented, multiple-callback compatible version of Curl::easy was substantially reworked from the previous Curl::easy release (1.21) by Cris Bailiff. .SH "AUTHORS" .IX Header "AUTHORS" Currently maintained by Cris Bailiff and Balint Szilakszi . .PP Original Author Georg Horn , with additional callback, pod and test work by Cris Bailiff and Forrest Cahoon . Sebastian Riedel added ::Multi and Anton Fedorov (datacompboy mail.ru) added ::Share. Balint Szilakszi repackaged the module into a more modern form. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2000\-2005,2008\-2014 Daniel Stenberg, Cris Bailiff, Sebastian Riedel, Balint Szilakszi et al. .PP 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 \s-1MIT\s0 license. .SH "SEE ALSO" .IX Header "SEE ALSO" .PP .PP \&\fBlibcurl\fR\|(3) .PP The development source code is also available: