首頁 >後端開發 >php教程 >CURL多執行緒不執行一直在請求

CURL多執行緒不執行一直在請求

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-08-04 09:21:101347瀏覽

程式碼如下
`

ini_set('max_execution_time',0);

for($i = 6055;$i >3055;$i--){

<code>$connomains[] = 'http://www.xxxxx.com/index.php&id='.$i;</code>

}

$mh = curl_multi_init();

foreach ($connomains as $i => $url) {

<code>$conn[$i]=curl_init($url);
curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle ($mh,$conn[$i]);</code>

}

$active = null;
do {

<code>$mrc = curl_multi_exec($mh, $active);</code>

} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {

<code>if (curl_multi_select($mh) != -1) {
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
}</code>

}

foreach ($connomains as $i => $url) {

<code>$res[$i]=curl_multi_getcontent($conn[$i]);
$res[$i] = json_decode($res[$i],true);
var_dump($res[$i]);
curl_close($conn[$i]);
</code>

}
print_r($res);

?>
`

頁面來源位址是http://www.4wei.cn/archives/1001877

回覆內容:

程式碼如下
`

ini_set('max_execution_time',0);

for($i = 6055;$i >3055;$i--){

<code>$connomains[] = 'http://www.xxxxx.com/index.php&id='.$i;</code>

}

$mh = curl_multi_init();

foreach ($connomains as $i => $url) {

<code>$conn[$i]=curl_init($url);
curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle ($mh,$conn[$i]);</code>

}

$active = null;
do {

<code>$mrc = curl_multi_exec($mh, $active);</code>

} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {

<code>if (curl_multi_select($mh) != -1) {
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
}</code>

}

foreach ($connomains as $i => $url) {

<code>$res[$i]=curl_multi_getcontent($conn[$i]);
$res[$i] = json_decode($res[$i],true);
var_dump($res[$i]);
curl_close($conn[$i]);
</code>

}
print_r($res);

?>
`

頁面來源位址是http://www.4wei.cn/archives/1001877

程式碼的意思是請求3000次後在執行輸出,把次數改小一點看看

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn