使用bash或file_get_contents启动PHP curl - 慢

时间:2013-04-15 11:49:13

标签: php performance curl

我有一个简单的PHP curl脚本,可以检查我的localhost是否有更新等。如果我在浏览器中打开.php,它会很快运行 - 它会立即加载。但是,如果我想在另一个PHP文件中使用file_get_contents集成文件,或者只是测试 - 通过bash运行它 - 它需要5秒才能完成!!文本响应本身几乎立即出现,但随后光标闪烁3-5秒,然后才完成请求。

如何让curl脚本不需要这么长时间来清理它或者它做了多长时间呢?

$url='http://nodes:1041/?request=speed';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$store = curl_exec($ch);
$array = json_decode($store, true);

if(!$array['nodes']) {
    echo 'Nothing running';
} else {
    foreach($array['nodes'] as $key => $speed) {
        $upload += $speed[0];
        $dnload += $speed[1];
    }
}

echo 'Down: ' . $dnload . '/s\n';
echo 'Up: ' . $upload .'/s\n';

curl_close($ch);

0 个答案:

没有答案