php-curl非常慢,total_time只有一些时间

时间:2014-02-16 10:24:19

标签: php curl

我有这个脚本

function curl_file_get_contents($url)
{
 $curl = curl_init();

 curl_setopt($curl, CURLOPT_HEADER, 0);

 curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0');

 curl_setopt($curl,CURLOPT_URL,$url); //The URL to fetch. This can also be set when initializing a session with curl_init().
 curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
 curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5); //The number of seconds to wait while trying to connect.  


 curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.   

 $contents = curl_exec($curl);

if(curl_exec($curl) === false)
{
    echo 'Curl error: ' . curl_error($curl);
}
else
{
    $info = curl_getinfo($curl);
    echo "\nOperation completed in ".$info['total_time']." without any errors\n";
    //print_r($info);
}

 curl_close($curl);
 return $contents;
}

这是日志的输出:

[content_type] => text/xml;charset=UTF-8
[http_code] => 200
[header_size] => 191
[request_size] => 591
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 26.400935
[namelookup_time] => 0.000829
[connect_time] => 0.000864
[pretransfer_time] => 0.001079
[size_upload] => 0
[size_download] => 123381
[speed_download] => 4673
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.317703
[redirect_time] => 0
[certinfo] => Array
    (
    )

[primary_ip] => 176.32.110.148
[primary_port] => 80
[local_ip] => 37.187.61.23
[local_port] => 46221
[redirect_url] => 

任何人都可以解释为什么total_time非常高?这种情况只发生几次,经常在夜间(约凌晨2点,凌晨3点)发生。

这是我的debian服务器上安装的版本:

root@vps31881:~# curl -V
curl 7.26.0 (i486-pc-linux-gnu) libcurl/7.26.0 OpenSSL/1.0.1e zlib/1.2.7 libidn/1.25 libssh2/1.4.2 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp 
Features: Debug GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP 

和php:

root@vps31881:~# php -v
PHP 5.4.4-14+deb7u3 (cli) (built: Jul 17 2013 17:51:10) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

如果我按终端运行curl,同时使用相同的url,那么速度非常快,我无法解释这个!

0 个答案:

没有答案