Jump to content
php.lv forumi

curl_multi_exec un limits uz download


kapec gan ne

Recommended Posts

$arr masiva glabajs peimeram 3000 linku

vajadzetu partaisit funkciju ta, lai vertu vala tos 3000 linkus pa 10, nevis uzreiz visus :)

function func1($arr){
$hArr = array();
$results = array();
foreach($arr as $val){
   	$h = curl_init();
   	curl_setopt($h,CURLOPT_URL,$val);
   	curl_setopt($h,CURLOPT_HEADER,0);
   	curl_setopt($h,CURLOPT_RETURNTRANSFER,1);
   	array_push($hArr,$h);
}
$mh = curl_multi_init();
foreach($hArr as $k => $h)
   	curl_multi_add_handle($mh,$h);

$running = null;
do{
   	curl_multi_exec($mh,$running);
}while($running > 0);
foreach($hArr as $k => $h){
   	$res = curl_multi_getcontent($h);
               //..
       	}
foreach($hArr as $k => $h){
   	curl_multi_remove_handle($mh,$h);
}
curl_multi_close($mh);
return $results;
}

 

EDIT: kaut ka apmeram sadi.. neesmu vel parbaudijis

function func1($arr){
$hArr = array();
$results = array();
$count=0;
for ($i = 0; $i < count($arr); $i++) {
   	$h = curl_init();
   	curl_setopt($h,CURLOPT_URL,$arr[$i]);
   	curl_setopt($h,CURLOPT_HEADER,0);
   	curl_setopt($h,CURLOPT_RETURNTRANSFER,1);
   	array_push($hArr,$h);

       if($count>9 || $i==count($arr)-1){
       	$mh = curl_multi_init();
       	foreach($hArr as $k => $h)
           	curl_multi_add_handle($mh,$h);

       	$running = null;

       	do{
           	curl_multi_exec($mh,$running);
       	}while($running > 0);

       	foreach($hArr as $k => $h){
    			$res = curl_multi_getcontent($h);
    			//..
       	}

       	foreach($hArr as $k => $h){
           	curl_multi_remove_handle($mh,$h);
       	}

           curl_multi_close($mh);
       	$count = 0;
   	}
  	$count++;
}
return $results;
}

Edited by kapec gan ne
Link to comment
Share on other sites

function func1($arr){
$hArr = array();
$results = array();
$count=0;
for ($i = 0; $i < count($arr); $i++) {
   	$h = curl_init();
   	curl_setopt($h,CURLOPT_URL,$arr[$i]);
   	curl_setopt($h,CURLOPT_HEADER,0);
   	curl_setopt($h,CURLOPT_RETURNTRANSFER,1);
   	array_push($hArr,$h);

   	if($count>9 || $i==count($arr)-1){
       	$mh = curl_multi_init();
       	print_r($hArr);

       	foreach($hArr as $k => $h){
           	curl_multi_add_handle($mh,$h);
       	}

       	$running = null;

       	do{
           	curl_multi_exec($mh,$running);
       	}while($running > 0);

  //.....
       	foreach($hArr as $k => $h){
           	curl_multi_remove_handle($mh,$h);
       	}
       	curl_multi_close($mh);
       	$hArr = array();
       	$count = 0;
   	}


  	$count++;


}
return $results;
}

strada ciesami :P

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...