先日(WordPressのパフォーマンスを上げる為、APCを導入しました)導入したAPCを別のサーバにも設定しようと思い、APCのインストール作業を始めたら、エラーが出ました。
調べてみると、PHP 5.5 からは、APCではなく、OPcache を使う形になったようです。
そこで、OPcacheを導入しましたので、その記録となります。
1.APCのインストールでエラー
pecl でインストールを実行すると、「apc_compile.lo」でエラーが出ました。
# pecl list (no packages installed from channel pecl.php.net) # pecl install APC downloading APC-3.1.13.tgz ... Starting to download APC-3.1.13.tgz (171,591 bytes) .....................................done: 171,591 bytes 55 source files, building running: phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 Enable internal debugging in APC [no] : Enable per request file info about files used from the APC cache [no] : Enable spin locks (EXPERIMENTAL) [no] : Enable memory protection (EXPERIMENTAL) [no] : Enable pthread mutexes (default) [no] : Enable pthread read/write locks (EXPERIMENTAL) [yes] : (中略) /tmp/pear/temp/APC/apc_compile.c:2416: error: ‘zend_trait_precedence’ has no member named ‘function’ /tmp/pear/temp/APC/apc_compile.c:2417: error: ‘zend_trait_precedence’ has no member named ‘function’ /tmp/pear/temp/APC/apc_compile.c:2417: error: ‘zend_trait_precedence’ has no member named ‘function’ make: *** [apc_compile.lo] Error 1 ERROR: `make' failed #
調べてみると、以下のサイトで分かりました。
http://serverfault.com/questions/533226/error-installing-apc-in-apache2-vps-with-php-5-5-1
PHP 5.5 からは、OPcache という機能が付いているとの事です。
2.OPcache設定
早速、OPcache の設定をする事にしました。
http://www.php.net/manual/en/opcache.installation.php
を参考にしながらの設定です。
php.ini で以下の設定を行いました。集約して記載しています。
zend_extension=/usr/local/lib/php/extensions/no-debug-zts-20121212/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
設定内容の説明は以下のURLで確認できます。
http://php.net/manual/ja/opcache.configuration.php
設定後、apache は再起動します。
3.php で確認
php コマンドで確認してみます。
# php -v PHP 5.5.1 (cli) (built: Aug 12 2013 23:59:09) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies #
OPcache が表示されています。
次は「php -i」で確認してみます。
# php -i | grep opcache 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.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 => 0xFFFFFFFF => 0xFFFFFFFF opcache.preferred_memory_model => no value => no value opcache.protect_memory => 0 => 0 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 #
opcache.enable が「On」になっていたり、設定が反映されています。
あとは、どのくらいパフォーマンスが改善されるかです。
あらためて効果測定をしてみたいと思います。