一個優秀網站速度一定是非常快的,所以我們建設的網站一定要保證速度,靜態文件方面我們可以啓用 cdn 來加速,動態腳本的優化我們只能儘量的減少查詢次數以及提高服務器的配置。下面上一個輸出 WordPress 執行效率的代碼。

<?php
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function start()
{
$this->StartTime = $this->get_microtime();
}
function stop()
{
$this->StopTime = $this->get_microtime();
}
function spent()
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}
}
$runtime= new runtime;
$runtime->start();
$a = 0;
for($i=0; $i<1000000; $i++)
{
$a += $i;
}
$runtime->stop();
echo "頁面執行時間: ".$runtime->spent()." 毫秒";
?>

將以上代碼放到 footer.php 適當的位置,就可以了看到 WordPress 當前頁面的執行效率了。