多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 背景介绍 [XCache][1] 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接使用缓冲区已编译的代码从而提高速度. 通常能够提高您的页面生成速率 **2 到5** 倍, 降低服务器负载。 ### yum安装 ~~~ yum install -y php-xcache ~~~ ### 编译安装 ~~~ # tar xf xcache-3.1.tar.bz2 # cd xcache-3.1 # 获取php的配置信息 # /usr/local/php/bin/phpize # ./configure # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make && make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20121212/ ~~~ 不用指定安装prefix,会默认安装到php的目录中 ### 整合php和xcache 首先将xcache提供的样例配置导入php.ini ~~~ # cp xcache.ini /etc/php.d ~~~ 说明:xcache.ini文件在xcache的源码目录中。 接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行,不同xcache版本略有不同 #### xcache3.0.0 ~~~ [xcache-common] zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so ~~~ #### xcache3.1 ~~~ [xcache-common] extension = /usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so ~~~ >[danger] 注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。 #### xcache3.2 ~~~ [xcache-common] extension = "xcache.so" ~~~ 此处不用修改 ### 配置文件说明 ~~~ [xcache] ; ini only settings, all the values here is default unless explained ; select low level shm implemenation xcache.shm_scheme = "mmap" #shm=shared memory共享内存 mmap=memory map 内存映射,一段内存可以让多个进程同时访问 ; to disable: xcache.size=0 ; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows xcache.size = 60M ; set to cpu count (cat /proc/cpuinfo |grep -c processor) xcache.count = 1 ; just a hash hints, you can always store count(items) > slots xcache.slots = 8K ; ttl of the cache item, 0=forever 生存周期,过期时间 xcache.ttl = 0 ; interval of gc scanning expired items, 0=no scan, other values is in seconds xcache.gc_interval = 0 ~~~ #gc:grabage colletion垃圾回收,0代表不扫描;扫描也会带来系统开销 ### 测试 在index.php中添加phpinfo();并测试查看xcache是有已启动 ![](http://om4h63cja.bkt.clouddn.com/17-6-16/61014530.jpg) [1]:http://xcache.lighttpd.net/wiki/ReleaseArchive