Curl_multi_xxx导致连接重置

时间:2015-07-15 06:47:48

标签: php curl

我使用curl_multi同时请求url。它适用于几个循环(大约10个),但我的网页将得到一个" net :: err_CONNECTION_RESET"几秒钟后。
我试着找出哪一行让我的页面失效,然后我发现它可能是curl_multi_exec或curl_multi_select。这个页面可以在几乎相同的环境中运行在我朋友的计算机上(Win7和xampp的默认设置,但可能有不同的版本)。
什么可能导致curl_multi_exec或curl_multi_select出错?

<?php
set_time_limit(0);
include 'tool_jsonRW.php';
error_reporting(E_ALL);
$url_array = array();
$data = array();
$filename = 'start.txt';
$file_handle = fopen($filename, "r");
$flag = fread($file_handle, filesize($filename));
fclose($file_handle);
$mh = curl_multi_init(); // multi curl handler

while(strcmp($flag, '1') == 0){
    $url_array = readJson("ip_list.json");
    $url_array = $url_array['rows'];

    $i = 0;
    foreach($url_array as $url) {
        $url = "http://127.0.0.1/proxy/MGCProxy_0.16.15.0701.0/MGCProxy_0.16.15.0701.0/MGCProxy/mgc_list_17.php?IP=".$url;
        echo '<pre>url  ', print_r($url, true), '</pre>'."\n";
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);

        curl_multi_add_handle($mh, $ch); //
        $handle[$i++] = $ch;
    }

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

    /* 移除 handle*/
    foreach($handle as $ch) {
        curl_multi_remove_handle($mh, $ch);
    }

    usleep(500);
    $file_handle = fopen($filename, "r");

    $flag = fread($file_handle, filesize($filename));

    fclose($file_handle);

    ++$a;
}
curl_multi_close($mh);
?>

这是Apache的错误日志,我是网络开发的新手,请让我知道我应该发布什么来帮助我们帮助我:)

[Wed Jul 15 14:43:11.175407 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00428: Parent: child process 5940 exited with status 3221225477 -- Restarting.<br>
[Wed Jul 15 14:43:11.250407 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00455: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9 configured -- resuming normal operations<br>
[Wed Jul 15 14:43:11.250407 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00456: Apache Lounge VC11 Server built: Nov 21 2013 20:13:01<br>
[Wed Jul 15 14:43:11.250407 2015] [core:notice] [pid 8384:tid 256] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'<br>
[Wed Jul 15 14:43:11.255407 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00418: Parent: Created child process 6660<br>
[Wed Jul 15 14:43:11.680408 2015] [mpm_winnt:notice] [pid 6660:tid 268] AH00354: Child: Starting 150 worker threads.<br>
[Wed Jul 15 14:43:18.430417 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00428: Parent: child process 6660 exited with status 3221225477 -- Restarting.<br>
[Wed Jul 15 14:43:18.505417 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00455: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9 configured -- resuming normal operations<br>
[Wed Jul 15 14:43:18.505417 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00456: Apache Lounge VC11 Server built: Nov 21 2013 20:13:01<br>
[Wed Jul 15 14:43:18.505417 2015] [core:notice] [pid 8384:tid 256] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'<br>
[Wed Jul 15 14:43:18.510417 2015] [mpm_winnt:notice] [pid 8384:tid 256] AH00418: Parent: Created child process 9264<br>
[Wed Jul 15 14:43:18.890418 2015] [mpm_winnt:notice] [pid 9264:tid 268] AH00354: Child: Starting 150 worker threads.

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,它是由php_curl.dll的版本引起的。如果您使用的版本低于7.36,则

时页面将崩溃
curl_multi_exec($mh, $running);
curl_multi_select($mh);

只需更新dll的版本,然后curl_multi运行良好!