Rumah >pembangunan bahagian belakang >tutorial php >CURL多线程不执行一直在请求

CURL多线程不执行一直在请求

WBOY
WBOYasal
2016-08-04 09:21:101320semak imbas

代码如下
`

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次后在执行输出,把次数改小点看看

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn