Loading... <h4><font style="font-weight: normal">PHP 5.5 以后内建了 </font><code><font style="font-weight: normal">OpCache</font></code><font style="font-weight: normal"> ,我们启用即可 </font><code><font style="font-weight: normal">OpCache</font></code><font style="font-weight: normal"> 的加速原理是把编译后的 </font><code><font style="font-weight: normal">bytecode</font></code><font style="font-weight: normal"> 存储在内存里面, 避免重复编译 PHP 所造成的资源浪费.</font></h4> <p>虽然内建了, 但是默认没有启用:<pre>军哥lnmp <code> Ubuntu 14.04 nginx1.6.2 mariadb5.5.41 php5.6.5 </code></pre> <h5> </h5> <h5>修改 php.ini 文件</h5><pre><code>sudo vim /usr/local/php/etc//php.ini</code></pre> <p>在文件最后面加入:<pre><code> ;添加opcache的模块 zend_extension=opcache.so ; 开关打开 opcache.enable=1 ; 可用内存, 酌情而定, 单位 megabytes opcache.memory_consumption=256 ; 对多缓存文件限制, 命中率不到 100% 的话, 可以试着提高这个值 opcache.max_accelerated_files=5000 ; Opcache 会在一定时间内去检查文件的修改时间, 这里设置检查的时间周期, 默认为 2, 定位为秒 opcache.revalidate_freq=240 </code></pre> <p> <p>重启服务器<pre><code>sudo service php-fpm restart sudo service nginx restart</code></pre> <h4>APC VS OpCache</h4> <p>APC 是将要被遗弃的项目, PHP 5.5 都不支持, 而在 PHP 5.5 和 5.6 版本, OpCache 是默认内建的, 并且支持 5.2 到 5.4 的安装. <h4>查看效果</h4> <ul> <li>拥有漂亮的图形化界面的项目 : <span class="external-link"><a class="no-external-link" href="https://github.com/PeeHaa/OpCacheGUI" target="_blank"><i data-feather="external-link"></i>https://github.com/PeeHaa/OpCacheGUI</a></span> <li>单文件, 方便部署的项目: <span class="external-link"><a class="no-external-link" href="https://github.com/rlerdorf/opcache-status" target="_blank"><i data-feather="external-link"></i>https://github.com/rlerdorf/opcache-status</a></span></li></ul> <p><a href="https://www.crazycen.com/usr/uploads/2015/02/image2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://www.crazycen.com/usr/uploads/2015/02/image_thumb2.png" width="781" height="425"></a></p> Last modification:October 6, 2023 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏
One comment
提高PHP性能是件好事啊。