PHP 常用加速器 APC,eAccelerator & XCache

孤者浪人 提交于 2020-01-26 01:09:48

PHP 加速器是一个为了提高 PHP 执行效率,从而缓存起 PHP 的操作码,这样 PHP 后面执行就不用解析转换了,可以直接调用 PHP 操作码,这样速度上就提高了不少。

Apache 中使用 mod_php 的请求、响应执行流程:
1、Apache 接收请求
2、Apache 传递请求给 mod_php
3、mod_php 定位磁盘文件,并加载到内存中
4、mod_php 编译源代码成为 opcode 树
5、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/

XCache:XCache 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接使用缓冲区已编译的代码从而提高速度. 通常能够提高您的页面生成速率 2 到5 倍, 降低服务器负载(截取自:http://baike.baidu.com/view/1999371.htm

链接地址:http://xcache.lighttpd.net/wiki/WikiStart.

 

APC VS eAccelerator VS XCache 

速度比较

图中可以看到:APC,XCache,eAccelerator 的测试数据,相对来说 XCache 表现最好,但是每个加速器都有各种微调参数,具体视部署环境而定。

 

版本存活状态

(截取自:http://en.wikipedia.org/wiki/List_of_PHP_accelerators

Alternative PHP Cache (APC)

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

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.

  • Website: http://eaccelerator.net/
  • PHP version: Supports PHP 4 and all PHP 5 thread-safe releases including 5.3 from version 0.9.6; breaks on 5.4. In older releases, the encoder will only work with PHP versions from the 4.x.x branch. eAccelerator will not work with any other versions of PHP. eAccelerator can only be used with the thread-safe version of PHP. (This seems not to be true, this version works for my php non-thread-safe installation: http://eac.qme.nl/eAccelerator_v1_0_svn427_for_v5_3_X-VC9.zip)
  • Latest stable version: 0.9.6.1 (2010-05-31)
  • Status: Potentially dead (no new releases since May 2010). UPDATE from eaccelerator.net: 25 Jul 2012 - Project was taken by Hans Rakers and moved to Github, master branch does support PHP 5.4
  • Download link: (look for latest versions) http://eaccelerator.net/download page on SourceForge
  • Official installation help: https://eaccelerator.net/wiki/InstallFromSource

XCache

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 已经接近死亡状态了。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!