Zend OPCache加速PHP使用说明
Zend Opcache配置方法
Zend Opcache 已经集成在了PHP 5.5里面,编译安装PHP5.5的时候加上--enable-opcache就行了。但也支持低版本的 PHP 5.2.*, 5.3.*, 5.4.*,未来会取消对5.2的支持,下面是我在PHP 5.4下的安装方法:
依次执行下面的命令
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4124')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4124>wget http://pecl.php.net/get/zendopcache-7.0.2.tgz
tar xzf zendopcache-7.0.2.tgz
cd zendopcache-7.0.2
phpize
如果找不到phpize 的话自己找PHP路径,我的在/usr/local/php/bin/phpize,下面这行也要按你的php.ini路径自行修改
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4587')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4587>./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
如果显示Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
表示安装完成,下面要修改php的配置文件让它生效
在 php.ini 的最后面加入下面几行
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1039')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1039>zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
128意思是给它分配128M内存,然后重启apache,用phpinfo查看是否生效,显示下面的信息就说明生效了
<h2>Zend Opcache是否生效</h2>可以通过phpinfo查看是否生效,下图是我的配置PHP扩展:
Zend Opcache已经生效了,如果不行可参考正同方法来解决
配置OPC还是比较简单的,eAccelerator被我干掉了,重复的功能。配置如下:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9786')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9786>wget http://pecl.php.net/get/zendopcache-7.0.2.tgz
tar xzf zendopcache-7.0.2.tgz
cd zendopcache-7.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install接着呢,配置下php.ini,在最后加上:
[opcache]
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1483')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1483>zend_extension=opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.enable=1
一般来说,按照以往的经验,如果加在ZendGuardLoader之前会稳定多
您可能感兴趣的文章:
Zend OPCache加速PHP使用说明
在CentOS上php5.6怎么安装?
如何在Ubuntu 18.04和16.04上安装PHP(7.3,7.2和7.0)?
如何通过PPA在Ubuntu上安装PHP7
opcache PHP新的字节码缓存扩展详解
PHP字节码缓存和内置服务器
用Zend Encode编写开发PHP程序
ubuntu怎么安装PHP
centos怎么更新php
给PHP安装配置Opcache缓存功能