4en3rgY Romania
curl multithread php 2z8bv910
Welcome To 4EN3RGY Romania
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!

4en3rgY Romania


Nu sunteti conectat. Conectați-vă sau înregistrați-vă

curl multithread php

Vezi subiectul anterior Vezi subiectul urmator In jos  Mesaj [Pagina 1 din 1]

1curl multithread php Empty curl multithread php Dum 15 Ian 2012, 16:59

KiddOx <3.

KiddOx <3.Membru

Cod:
< ?php

//functia curl de procesare in paralel

function curl($nodes, $referer) {

// atentie la functia asta daca aveti safe mode on nu functioneaza
set_time_limit(0);
if(!$referer)
$referer = $nodes[0];
 
$node_count = count($nodes);
$curl_arr = array();
$master = curl_multi_init(); //initiem multi curl

 

for($i = 0; $i < $node_count; $i++) { //pentru fiecare nod (link)

//cream linkul.
$curl_arr[$i] = curl_init($nodes[$i]);
curl_setopt($curl_arr[$i],CURLOPT_FRESH_CONNECT,true);
curl_setopt($curl_arr[$i],CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_arr[$i],CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_arr[$i],CURLOPT_REFERER,$referer);
curl_setopt($curl_arr[$i],CURLOPT_TIMEOUT,30);

//il adaugam la masterul multi-curl
curl_multi_add_handle($master, $curl_arr[$i]);
}
$finalresult = array();
$returnedOrder = array();

do{
//extragem contentul
curl_multi_exec($master, $running);
$info = curl_multi_info_read($master);
if($info['handle']) {
$finalresult[] = curl_multi_getcontent($info['handle']);

$returnedOrder[] = array_search($info['handle'], $curl_arr, true);
curl_multi_remove_handle($master, $info['handle']);
curl_close($curl_arr[end($returnedOrder)]);

}

$previousActive = $running;
}
while($running > 0);
//returnam
return array_combine($returnedOrder, $finalresult);
curl_multi_close($master);
}

// specificati adresele paginilor in array
$urls = array( 'link1', 'link2' );
curl($urls, null);
?>

Vezi subiectul anterior Vezi subiectul urmator Sus  Mesaj [Pagina 1 din 1]

Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum

 

Copyright @ 2010-2024 by 4en3rgY ~> All rights reserved.