Php 如何减少curl调用的时间?

Php 如何减少curl调用的时间?,php,curl,Php,Curl,由于某种原因,我的卷发呼叫非常慢。这是我使用的代码 $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:','Accept: application/xml')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE

由于某种原因,我的卷发呼叫非常慢。这是我使用的代码

            $ch = curl_init();

        curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:','Accept: application/xml'));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        //curl_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        //curl_setopt($ch, CURLOPT_NOBODY, !($options['return_body']));
        curl_setopt($ch, CURLOPT_SSLVERSION, 3);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
        curl_setopt($ch,CURLOPT_TIMEOUT_MS,0);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
        $result = curl_exec($ch);

        $curl_errno = curl_errno($ch);
        $curl_error = curl_error($ch);

        curl_close($ch);
我们有9000张唱片要取 花了56分钟

为了检查每条记录的执行时间,我使用curl_getinfo()函数; 每条记录大约需要0.46秒

我想缩短这几秒钟


幸运的是,它可以减少到15分钟吗?

尝试再设置一个卷发选项

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
同时尝试使用
curl\u multi\u exec

使用文件获取内容($url)

用户代理示例

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>


是否尝试过以其他方式检查响应时间?就像用curl cli或wget抓取一条记录一样?您可以使用异步调用-
http://www.waytoblogger.com/2014/01/12/how-to-make-asynchronous-rest-call-using-curl-in-php/
-这可能会对您有所帮助。您不能真正“缩短时间”,而是由远程服务器决定何时响应。‌​-php中的curl/link未打开@pravahy
文件获取内容
over
curl