出于某种原因,我的卷曲呼叫很慢。这是我使用的代码。
$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分钟吗?
答案 0 :(得分:0)
尝试再设置一个cURL选项。
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
还尝试使用curl_multi_exec
。
答案 1 :(得分:0)
使用file_get_contents($ 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);
?>