note 115990 added to function.curl-multi-exec
| From: | jorov at mail dot bg | Date: | Thu, 23 Oct 2014 15:22:16 +0000 |
| Subject: | note 115990 added to function.curl-multi-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200721@lists.php.net to get a copy of this message | ||
I tried Daniel G Zylberberg's function and
it was not working the way it was posted.
I made some changes to get it work and here is what I use:
function multiCurl($res, $options=""){
if(count($res)<=0) return False;
$handles = array();
if(!$options) // add default options
$options = array(
CURLOPT_HEADER=>0,
CURLOPT_RETURNTRANSFER=>1,
);
// add curl options to each handle
foreach($res as $k=>$row){
$ch{$k} = curl_init();
$options[CURLOPT_URL] = $row['url'];
$opt = curl_setopt_array($ch{$k}, $options);
var_dump($opt);
$handles[$k] = $ch{$k};
}
$mh = curl_multi_init();
// add handles
foreach($handles as $k => $handle){
$err = curl_multi_add_handle($mh, $handle);
}
$running_handles = null;
do {
curl_multi_exec($mh, $running_handles);
curl_multi_select($mh);
} while ($running_handles > 0);
foreach($res as $k=>$row){
$res[$k]['error'] = curl_error($handles[$k]);
if(!empty($res[$k]['error']))
$res[$k]['data'] = '';
else
$res[$k]['data'] = curl_multi_getcontent( $handles[$k] ); // get results
// close current handler
curl_multi_remove_handle($mh, $handles[$k] );
}
curl_multi_close($mh);
return $res; // return response
}
----
Server IP: 72.52.91.14
Probable Submitter: 84.21.200.11
----
Manual Page -- http://php.net/manual/en/function.curl-multi-exec.php
Edit -- https://master.php.net/note/edit/115990
Del: integrated -- https://master.php.net/note/delete/115990/integrated
Del: useless -- https://master.php.net/note/delete/115990/useless
Del: bad code -- https://master.php.net/note/delete/115990/bad+code
Del: spam -- https://master.php.net/note/delete/115990/spam
Del: non-english -- https://master.php.net/note/delete/115990/non-english
Del: in docs -- https://master.php.net/note/delete/115990/in+docs
Del: other reasons-- https://master.php.net/note/delete/115990
Reject -- https://master.php.net/note/reject/115990
Search -- https://master.php.net/manage/user-notes.php