1. 程式人生 > >PHP加速插件ZendOpcache使用

PHP加速插件ZendOpcache使用

get mha enter mbstring gre inter -m buffer 編譯

本文源鏈接地址:https:www.93bok.com

概述

Zend OPCache 的前身是Zend Optimizer + (Zend O+),於 2013年3月中旬改名為 Opcache。其通過 opcode 緩存和優化提供更快的 PHP 執行過程。它將預編譯的腳本文件存儲在共享內存中供以後使用,從而避免了從磁盤讀取代碼並進行編譯的時間消耗。同時,它還應用了一些代碼優化模式,使得代碼執行更快。

說明

PHP 在5.5發行版後自帶了Zend OPCache擴展,編譯的時候加上--enable-opcache就行了,PHP5.2,5.3,5.4版也可以使用,但需要自行下載擴展。

官方下載地址

http://pecl.php.net/package/ZendOpcache

一、如果是php5.5以上版本,如下重新編譯一下即可

1、先進入源碼目錄
cd /a01/apps/apps_src/php-7.1.7
2、查看之前的編譯參數

可以在phpinfo中查看,也可以以下命令

/a01/apps/php7/bin/php -i | grep configure
3、按照上一步查看的舊參數重新編譯,添加上--enable-opcach就行了
./configure --prefix=/a01/apps/php7 --with-config-file-path=/etc/php --with-mcrypt --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli --with-pdo-mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir --disable-rpath --enable-bcmath --enable-inline-optimization --with-curl --enable-mbstring --with-mhash --with-gd --with-openssl --enable-zip --with-bz2 --enable-ftp --with-gettext --enable-opcache

報錯

技術分享圖片

解決

export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib
4、安裝
make && make install
5、配置php.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
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
6、重啟php-fpm
systemctl restart php-fpm
7、phpinfo查看

技術分享圖片

二、如果是php5.5以下版本

1、下載
cd /a01/apps/apps_src/
wget http://pecl.php.net/get/zendopcache-7.0.5.tgz
2、解包
tar zxvf zendopcache-7.0.5.tgz
3、使用phpize生成configure
cd zendopcache-7.0.5
/a01/apps/php/bin/phpize
./configure --with-php-config=/a01/apps/php/bin/php-config
4、安裝
make && make install
5、配置php.ini
[opcache]
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
6、重啟php-fpm
systemctl restart php-fpm

PHP加速插件ZendOpcache使用