2014-06-09 34 views
0

由於某種原因,我的捲曲電話很慢。這是我使用的代碼。如何減少捲曲呼叫的時間?

  $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

試圖查詢的響應時間以任何其他方式?像用curl-cli或wget抓取一個記錄? – ztripez

+0

你可以使用異步調用 - http:// www.waytoblogger.com/2014/01/12/how-to-make-asynchronous-rest-call-using-curl-in-php /' - 這可能會幫助你。 – prava

+0

您無法真正「縮短時間」,因此需要由遠程服務器決定何時作出響應。 –

回答

0

嘗試設置一個更多的捲曲選項。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

也嘗試使用curl_multi_exec

0

使用的file_get_contents($網址)

例如與用戶代理

<?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); 
?> 
+0

爲什麼'file_get_contents'超過'curl'? –