


先日、php 5.4からphp 5.6にアップデートしました。
この時phpアクセラレータのapcが動作しなくて無効化していました。
再インストールすると途中、エラーでインストールできません。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# pecl uninstall apc # pecl install apc Starting to download APC-3.1.13.tgz (171,591 bytes) .....................................done: 171,591 bytes 55 source files, building running: phpize Configuring for: (snip) /var/tmp/APC/apc_cache.c:820:22: error: 'IS_CONSTANT_ARRAY' undeclared (first use in this function) case IS_CONSTANT_ARRAY: ^ make: *** [apc_cache.lo] 1 ERROR: `make' failed |
php 5.5からコードキャッシュはAPCからOPchaceに代わったそうです。
PHP5.5 のコードキャッシュは APC から Zend OPcache へ
http://www.1×1.jp/blog/2013/04/php55_replace_apc_with_zend_opcache.html
それではCentOS 7.2 & php 5.6にOPcacheをインストールしてみます。
- インストール
- 設定ファイル作成
- Apache再起動
- 確認
yumでパッケージがありましたので簡単インストールです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# yum search opcache 読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.riken.jp * epel: ftp.riken.jp * extras: ftp.riken.jp * remi: mirrors.mediatemple.net * remi-php56: mirrors.mediatemple.net * updates: ftp.riken.jp ================================================ N/S matched: opcache ================================================= php-opcache.x86_64 : The Zend OPcache php-pecl-zendopcache.x86_64 : The Zend OPcache php54-php-pecl-zendopcache.x86_64 : The Zend OPcache php55-php-opcache.x86_64 : The Zend OPcache php56-php-opcache.x86_64 : The Zend OPcache php70-php-opcache.x86_64 : The Zend OPcache php71-php-opcache.x86_64 : The Zend OPcache Name and summary matches only, use "search all" for everything. # yum info php56-php-opcache 読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.riken.jp * epel: ftp.riken.jp * extras: ftp.riken.jp * remi: mirrors.mediatemple.net * remi-php56: mirrors.mediatemple.net * updates: ftp.riken.jp 利用可能なパッケージ 名前 : php56-php-opcache アーキテクチャー : x86_64 バージョン : 5.6.22 リリース : 1.el7.remi 容量 : 100 k リポジトリー : remi 要約 : The Zend OPcache URL : http://www.php.net/ ライセンス : PHP 説明 : The Zend OPcache provides faster PHP execution through opcode caching and : optimization. It improves PHP performance by storing precompiled script : bytecode in the shared memory. This eliminates the stages of reading code from : the disk and compiling it on future access. In addition, it applies a few : bytecode optimization patterns that make code execution faster. # yum -y install php56-php-opcache (snip) インストール: php56-php-opcache.x86_64 0:5.6.22-1.el7.remi 依存性関連をインストールしました: audit-libs-python.x86_64 0:2.4.1-5.el7 checkpolicy.x86_64 0:2.1.12-6.el7 environment-modules.x86_64 0:3.2.10-10.el7 libcgroup.x86_64 0:0.41-8.el7 libsemanage-python.x86_64 0:2.1.10-18.el7 php56-php-common.x86_64 0:5.6.22-1.el7.remi php56-php-pecl-jsonc.x86_64 0:1.3.9-1.el7.remi php56-php-pecl-zip.x86_64 0:1.13.2-1.el7.remi php56-runtime.x86_64 0:2.1-5.el7.remi policycoreutils-python.x86_64 0:2.2.5-20.el7 python-IPy.noarch 0:0.75-6.el7 scl-utils.x86_64 0:20130529-17.el7_1 setools-libs.x86_64 0:3.3.7-46.el7 tcl.x86_64 1:8.5.13-8.el7 完了しました! # find / -name opcache.so /opt/remi/php56/root/usr/lib64/php/modules/opcache.so |
OPchaceをphpに組込むための設定ファイルを作成します。
1 2 3 4 5 6 7 8 9 10 11 12 |
# vi /etc/php.d/opcache.ini # cat /etc/php.d/opcache.ini zend_extension=/opt/remi/php56/root/usr/lib64/php/modules/opcache.so [opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 |
設定値は下記のサイトを参考にして下さい。
実行時設定
http://php.net/manual/ja/opcache.configuration.php
1 |
# apachectl restart |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# php -v PHP 5.6.22 (cli) (built: May 26 2016 15:36:45) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies # php -i | grep opcache /etc/php.d/opcache.ini opcache.blacklist_filename => no value => no value opcache.consistency_checks => 0 => 0 opcache.dups_fix => Off => Off opcache.enable => On => On opcache.enable_cli => On => On opcache.enable_file_override => Off => Off opcache.error_log => no value => no value opcache.fast_shutdown => 1 => 1 opcache.file_update_protection => 2 => 2 opcache.force_restart_timeout => 180 => 180 opcache.inherited_hack => On => On opcache.interned_strings_buffer => 8 => 8 opcache.load_comments => 1 => 1 opcache.log_verbosity_level => 1 => 1 opcache.max_accelerated_files => 4000 => 4000 opcache.max_file_size => 0 => 0 opcache.max_wasted_percentage => 5 => 5 opcache.memory_consumption => 128 => 128 opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF opcache.preferred_memory_model => no value => no value opcache.protect_memory => 0 => 0 opcache.restrict_api => no value => no value opcache.revalidate_freq => 60 => 60 opcache.revalidate_path => Off => Off opcache.save_comments => 1 => 1 opcache.use_cwd => On => On opcache.validate_timestamps => On => On |
どれ位速くなるのか? ちょっとテストしたけど逆に遅くなったような…
回線状況もあるけど、適当に設定したパラメーターの見直しも必要かな。