Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

實測對比:相同硬體下 CentOS 執行 PHP+MySQL 程式比 Windows Server 2003 快 2~4 倍

編輯:Linux 教學

雲端伺服器可隨意切換作業系統,筆者以單核 Xeon E5620 + 1GB RAM 環境,分別部署 Windows 2003 (IIS+MySQL+PHP) 與 CentOS 5.9 (Apache+MySQL+PHP),執行相同含資料庫查詢的 PHP 程式測試執行時間。

測試程式碼

$st = microtime(true);
// ... 含 MySQL 查詢邏輯 ...
echo "載入時間:" . (microtime(true) - $st);

三次測試結果對照

測試次Windows 2003 (秒)CentOS 5.9 (秒)倍數差距
10.01970.01131.74x
20.01190.00522.29x
30.01480.00473.15x

結論

  • 雖然瀏覽器體感差異不明顯,但在相同硬體、相同程式碼下,Linux 核心排程、記憶體管理與 I/O 路徑對動態語言執行效率確有優勢。
  • 若以 Web 伺服器為主要用途,Linux(CentOS/Ubuntu/Debian)為更具成本效益的選擇。

註:測試環境較舊,現代 PHP 7/8 + Nginx + PHP-FPM 在 Linux 上效能差距更大。

Copyright © Windows教程網 All Rights Reserved