在Windows LocalHost上缓慢下载速度

时间:2014-11-22 12:15:13

标签: php windows performance localhost

我在VDS上安装了localhost(xammp,wampserver)。当我尝试使用PHP Curl和file_get_contents获取文件时,下载速度非常低。我可以在10分钟内下载100mb文件。如果我尝试使用浏览器下载相同的文件,则持续时间仅为3秒。可能是什么原因? 谢谢你的兴趣。

1 个答案:

答案 0 :(得分:-1)

在特定URL上下载内容是互联网上的常见做法,特别是由于亚马逊,Alexa,Digg等提供的Web服务和API的使用增加.PHP的cURL库通常带有默认共享托管配置,允许Web开发人员完成此任务。

你可以尝试

/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

用法

$ returned_content = get_data(' http://davidwalsh.name'); //像这样的东西

或者,您可以远程使用file_get_contents函数,但许多主机不允许这样做。