大家知道目前PHP的缓存插件一般有三个:APC、eAccelerator、XCache,但未来它们可能都会消失,因为PHP 5.5已经集成Zend Opcache,功能和前三者相似但又有少许不同,缓存速度据说比它们更快(注意:只是据说,我没测试过)。
php5.5以后版本编译eAccelerator报错如下:
<ol class="dp-j"><li class="alt"><span><span>cd /usr/local/src/php-</span><span class="number">5.6</span><span>.</span><span class="number">0</span><span>/ext/opcache </span></span></li><li><span> </span></li><li class="alt"><span>/usr/local/webserver/php/bin/phpize </span></li><li><span> </span></li><li class="alt"><span>./configure --with-php-config=/usr/local/webserver/php/bin/php-config </span></li><li><span> </span></li><li class="alt"><span>make && make install </span></li></ol>
最好修改/etc/php.ini在最后加入:
<ol class="dp-j"><li class="alt"><span><span>opcache] </span></span></li><li><span> </span></li><li class="alt"><span>zend_extension=/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-<span class="number">20131226</span><span>/opcache.so </span></span></li><li><span> </span></li><li class="alt"><span>opcache.memory_consumption=<span class="number">128</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>opcache.interned_strings_buffer=<span class="number">8</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>opcache.max_accelerated_files=<span class="number">4000</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>opcache.revalidate_freq=<span class="number">60</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>opcache.fast_shutdown=<span class="number">1</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>opcache.enable_cli=<span class="number">1</span><span> </span></span></li></ol>重启php-fpm:<br />究其原因是PHP5.5以下版本有php_logos.c,php_logos.h等文件。
如果想在新版本继续用加速,目前知道是的php自带扩展 opcache。
<ol class="dp-j"><li class="alt"><span><span>1kill -USR2 `cat /usr/local/webserver/php/var/run/php-fpm.pid` </span></span></li></ol>
测试地址在https://gist.github.com/ck-on/4959032,把上面的代码保存为一个php文件放到你的网站目录下面打开就可以看到.