在这两者之间,哪一个更快?直接通过loadHTMLFile
或首先cURL
获取内容,然后转到loadHTML
$doc = new DOMDocument();
@$doc->loadHTMLFile($url);
或者
$doc = new DOMDocument();
$ch = curl_init();
$timeout = 500;
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);
@$doc->loadHTML($data);
答案 0 :(得分:1)
添加为脚本的最后一行,并尝试每种方法至少3次,以准确了解哪种方法最快。
Page generated in
<?php echo round((microtime(TRUE)-$_SERVER['REQUEST_TIME_FLOAT']), 4); ?>
seconds on <?php echo date("M jS Y"); ?>