开发者

curl_exec: 1-5 seconds for execution time?

In my php script I am using curl library and the function curl_exec takes 1-5 seconds to be executed ( and for some url it take 10 seconds as well ). It is normal ?

This is my script:

$ch = curl_init();
$timeout = 5;     
$url = "http://www.mashable.com/feed";
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_ex开发者_如何学编程ec($ch);
curl_close($ch);


It is normal ?

Totally depends on your connection, the target URLs, and the server it runs on. It's well possible that it's normal.

If you have command line access to your server, you could try replicating the actions in command line curl and see how long they take there; also try them from your local machine. If there are massive differences, there could be a networking or firewall issue.

But those kinds of loading times are not unheard of.


It doesn't have to be uncommon - you are under the same conditions as if you requested an URL with your own browser - connecting and exchanging requests will take some time and if the URL you are requesting is busy or on a slower connection, the time naturally increases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜