note 114879 added to function.curl-multi-getcontent
| From: | michael at xendica dot com | Date: | Sat, 19 Apr 2014 18:28:43 +0000 |
| Subject: | note 114879 added to function.curl-multi-getcontent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199298@lists.php.net to get a copy of this message | ||
This seems to work as expected for me - allowing me to get the content from a curl_multi operation
into variables :
(Thanks go to many other notes in related documentation (there is much copy/pasting) all I did was
add the relevant line(s))
<?
$aURLs = array("http://www.php.net","http://www.w3cschools.com");
// array of URLs
$mh = curl_multi_init(); // init the curl Multi
$aCurlHandles = array(); // create an array for the individual curl handles
foreach ($aURLs as $id=>$url) { //add the handles for each url
$ch = curl_setup($url,$socks5_proxy,$usernamepass);
$ch = curl_init(); // init curl, and then setup your options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // returns the result - very important
curl_setopt($ch, CURLOPT_HEADER, 0); // no headers in the output
$aCurlHandles[$url] = $ch;
curl_multi_add_handle($mh,$ch);
}
$active = null;
//execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
}
while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
/* This is the relevant bit */
// iterate through the handles and get your content
foreach ($aCurlHandles as $url=>$ch) {
$html = curl_multi_getcontent($ch); // get the content
// do what you want with the HTML
curl_multi_remove_handle($mh, $ch); // remove the handle (assuming you are done with it);
}
/* End of the relevant bit */
curl_multi_close($mh); // close the curl multi handler
?>
----
Server IP: 72.52.91.14
Probable Submitter: 196.210.205.28
----
Manual Page -- http://php.net/manual/en/function.curl-multi-getcontent.php
Edit -- https://master.php.net/note/edit/114879
Del: integrated -- https://master.php.net/note/delete/114879/integrated
Del: useless -- https://master.php.net/note/delete/114879/useless
Del: bad code -- https://master.php.net/note/delete/114879/bad+code
Del: spam -- https://master.php.net/note/delete/114879/spam
Del: non-english -- https://master.php.net/note/delete/114879/non-english
Del: in docs -- https://master.php.net/note/delete/114879/in+docs
Del: other reasons-- https://master.php.net/note/delete/114879
Reject -- https://master.php.net/note/reject/114879
Search -- https://master.php.net/manage/user-notes.php