PHP 加速器是一個爲了提升 PHP 執行效率,從而緩存起 PHP 的操做碼,這樣 PHP 後面執行就不用解析轉換了,能夠直接調用 PHP 操做碼,這樣速度上就提升了很多。php
Apache 中使用 mod_php 的請求、響應執行流程:
一、Apache 接收請求
二、Apache 傳遞請求給 mod_php
三、mod_php 定位磁盤文件,並加載到內存中
四、mod_php 編譯源代碼成爲 opcode 樹
五、mod_php 執行 opcode 樹緩存PHP 加速器相應的就是第四步,它的目的就是防止 PHP 每次請求都重複編譯PHP代碼,由於在高訪問量的網站上,大量的編譯每每沒有執行速度快呢?因此這裏面有個瓶頸就是PHP的重複編譯既影響了速度又加載了服務器負載,爲了解決此問題,PHP加速器就這樣誕生了。 服務器
APC:Alternative PHP Cache(APC)是 PHP 的一個免費公開的優化代碼緩存。它用來提供免費,公開而且強健的架構來緩存和優化 PHP 的中間代碼。
連接地址:http://php.net/manual/en/book.apc.php架構eAccelerator:eAccelerator 是一個自由開放源碼php加速器,優化和動態內容緩存,提升了 php 腳本的緩存性能,使得PHP腳本在編譯的狀態下,對服務器的開銷幾乎徹底消除。 它還有對腳本起優化做用,以加快其執行效率。使您的PHP程序代碼執效率能提升1-10倍(截取自:http://baike.baidu.com/view/1376127.htm)
連接地址:http://eaccelerator.net/ideXCache:XCache 是一個開源的 opcode 緩存器/優化器, 這意味着他可以提升您服務器上的 PHP 性能. 他經過把編譯 PHP 後的數據緩衝到共享內存從而避免重複的編譯過程, 可以直接使用緩衝區已編譯的代碼從而提升速度. 一般可以提升您的頁面生成速率 2 到5 倍, 下降服務器負載(截取自:http://baike.baidu.com/view/1999371.htm)
連接地址:http://xcache.lighttpd.net/wiki/WikiStart.svn
APC VS eAccelerator VS XCache 性能
速度比較測試
圖中能夠看到:APC,XCache,eAccelerator 的測試數據,相對來講 XCache 表現最好,可是每一個加速器都有各類微調參數,具體視部署環境而定。優化
版本存活狀態網站
(截取自:http://en.wikipedia.org/wiki/List_of_PHP_accelerators)
Alternative PHP Cache is a free, open source (PHP license) framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode compiler in shared memory.
eAccelerator was born in December 2004 as a fork of the Turck MMCache project. Turck MMCache was created by Dmitry Stogov and much of the eAccelerator code is still based on his work. eAccelerator also contained a PHP encoder and loader, but the development staff discontinued the encoder and removed this feature after December 2006.
XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load. It is tested on Linux and FreeBSD and supported under Windows, for thread-safe and non-thread-safe versions of PHP. This relatively new opcode caching software has been developed by mOo, one of developers of Lighttpd, to overcome some of the limitations of the existing solutions at that time; such as being able to use it with new PHP versions as they arrive.
目前 APC 和 XCache 都有積極的維護和更新版本,eAccelerator 已經接近死亡狀態了。