php 5.6を7.0にアップデートしたので次はOpcacheとAPCuを導入します。
APCがAPCuとZend OPcacheに取って代わられたワケ
http://qiita.com/nntsugu@github/items/63099b829befb57859d7
APCとZend OPcache/APCuの関係
APCが機能として持っている
opecode cache機能とdata cache機能を
PHP 5.5+では
opecode cache : Zend OPcache
data cache : APCu
で提供するようになりました。
※上記サイトから引用しました。
今回はAPCuも導入します。
- OPcacheのインストール
- OPcache設定ファイル作成
- 10-opcache.iniの編集
- APCuのインストール
- APCu設定ファイル作成
- 40-apcu.iniの編集
- OPcacheとAPCuの確認
- Apache再起動
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 |
# yum info php70-php-opcache 読み込んだプラグイン:fastestmirror 利用可能なパッケージ 名前 : php70-php-opcache アーキテクチャー : x86_64 バージョン : 7.0.8 リリース : 1.el7.remi 容量 : 118 k リポジトリー : remi 要約 : The Zend OPcache URL : http://www.php.net/ ライセンス : PHP 説明 : The Zend OPcache provides faster PHP execution through opcode caching : optimization. It improves PHP performance by storing precompiled scri : bytecode in the shared memory. This eliminates the stages of reading : the disk and compiling it on future access. In addition, it applies a : bytecode optimization patterns that make code execution faster. # yum -y install php70-php-opcache (snip) Running transaction インストール中 : php70-runtime-1.0-5.el7.remi.x86_64 インストール中 : php70-php-json-7.0.8-1.el7.remi.x86_64 インストール中 : php70-php-common-7.0.8-1.el7.remi.x86_64 インストール中 : php70-php-opcache-7.0.8-1.el7.remi.x86_64 検証中 : php70-php-opcache-7.0.8-1.el7.remi.x86_64 検証中 : php70-runtime-1.0-5.el7.remi.x86_64 検証中 : php70-php-json-7.0.8-1.el7.remi.x86_64 検証中 : php70-php-common-7.0.8-1.el7.remi.x86_64 インストール: php70-php-opcache.x86_64 0:7.0.8-1.el7.remi 依存性関連をインストールしました: php70-php-common.x86_64 0:7.0.8-1.el7.remi php70-php-json.x86_64 0:7.0.8-1.el7. php70-runtime.x86_64 0:1.0-5.el7.remi 完了しました! |
OPcacheの設定ファイルが/etc/opt/remi/php70/php.d/10-opcache.iniにあるのでこれを利用します。
1 |
# cp /etc/opt/remi/php70/php.d/10-opcache.ini /etc/php.d/ |
10-opcache.iniのzend_extension=を変更します。
これ以外の項目は必要に応じて変更して下さい。
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# vi /etc/php.d/10-opcache.ini # cat /etc/php.d/10-opcache.ini ; Enable Zend OPcache extension module zend_extension=/opt/remi/php70/root/usr/lib64/php/modules/opcache.so ; Determines if Zend OPCache is enabled opcache.enable=1 ; Determines if Zend OPCache is enabled for the CLI version of PHP ;opcache.enable_cli=0 ; The OPcache shared memory storage size. opcache.memory_consumption=128 ; The amount of memory for interned strings in Mbytes. opcache.interned_strings_buffer=8 ; The maximum number of keys (scripts) in the OPcache hash table. ; Only numbers between 200 and 100000 are allowed. opcache.max_accelerated_files=4000 ; The maximum percentage of "wasted" memory until a restart is scheduled. ;opcache.max_wasted_percentage=5 ; When this directive is enabled, the OPcache appends the current working ; directory to the script key, thus eliminating possible collisions between ; files with the same name (basename). Disabling the directive improves ; performance, but may break existing applications. ;opcache.use_cwd=1 ; When disabled, you must reset the OPcache manually or restart the ; webserver for changes to the filesystem to take effect. ;opcache.validate_timestamps=1 ; How often (in seconds) to check file timestamps for changes to the shared ; memory storage allocation. ("1" means validate once per second, but only ; once per request. "0" means always validate) ;opcache.revalidate_freq=2 ; Enables or disables file search in include_path optimization ;opcache.revalidate_path=0 ; If disabled, all PHPDoc comments are dropped from the code to reduce the ; size of the optimized code. ;opcache.save_comments=1 ; If enabled, a fast shutdown sequence is used for the accelerated code ;opcache.fast_shutdown=0 ; Allow file existence override (file_exists, etc.) performance feature. ;opcache.enable_file_override=0 ; A bitmask, where each bit enables or disables the appropriate OPcache ; passes ;opcache.optimization_level=0xffffffff ;opcache.inherited_hack=1 ;opcache.dups_fix=0 ; The location of the OPcache blacklist file (wildcards allowed). ; Each OPcache blacklist file is a text file that holds the names of files ; that should not be accelerated. opcache.blacklist_filename=/etc/opt/remi/php70/php.d/opcache*.blacklist ; Allows exclusion of large files from being cached. By default all files ; are cached. ;opcache.max_file_size=0 ; Check the cache checksum each N requests. ; The default value of "0" means that the checks are disabled. ;opcache.consistency_checks=0 ; How long to wait (in seconds) for a scheduled restart to begin if the cache ; is not being accessed. ;opcache.force_restart_timeout=180 ; OPcache error_log file name. Empty string assumes "stderr". ;opcache.error_log= ; All OPcache errors go to the Web server log. ; By default, only fatal errors (level 0) or errors (level 1) are logged. ; You can also enable warnings (level 2), info messages (level 3) or ; debug messages (level 4). ;opcache.log_verbosity_level=1 ; Preferred Shared Memory back-end. Leave empty and let the system decide. ;opcache.preferred_memory_model= ; Protect the shared memory from unexpected writing during script execution. ; Useful for internal debugging only. ;opcache.protect_memory=0 ; Allows calling OPcache API functions only from PHP scripts which path is ; started from specified string. The default "" means no restriction ;opcache.restrict_api= ; Enables and sets the second level cache directory. ; It should improve performance when SHM memory is full, at server restart or ; SHM reset. The default "" disables file based caching. ; RPM note : file cache directory must be owned by process owner ; for mod_php, see /etc/opt/remi/php70/httpd/conf.d/php.conf ; for php-fpm, see /etc/opt/remi/php70/php-fpm.d/*conf ;opcache.file_cache= ; Enables or disables opcode caching in shared memory. ;opcache.file_cache_only=0 ; Enables or disables checksum validation when script loaded from file cache. ;opcache.file_cache_consistency_checks=1 ; Enables or disables copying of PHP code (text segment) into HUGE PAGES. ; This should improve performance, but requires appropriate OS configuration. opcache.huge_code_pages=1 |
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 |
# yum info php70-php-pecl-apcu 利用可能なパッケージ 名前 : php70-php-pecl-apcu アーキテクチャー : x86_64 バージョン : 5.1.5 リリース : 1.el7.remi 容量 : 69 k リポジトリー : remi 要約 : APC User Cache URL : http://pecl.php.net/package/APCu ライセンス : PHP 説明 : APCu is userland caching: APC stripped of opcode caching. : : APCu only supports userland caching of variables. : : The php70-php-pecl-apcu-bc package provides a drop : in replacement for APC. : : Package built for PHP 7.0 as Software Collection (php70 by remi). # yum -y install php70-php-pecl-apcu (snip) Running transaction インストール中 : php70-php-pecl-apcu-5.1.5-1.el7.remi.x86_64 1/2 インストール中 : php70-php-pecl-apcu-bc-1.0.3-1.el7.remi.x86_64 2/2 検証中 : php70-php-pecl-apcu-bc-1.0.3-1.el7.remi.x86_64 1/2 検証中 : php70-php-pecl-apcu-5.1.5-1.el7.remi.x86_64 2/2 インストール: php70-php-pecl-apcu.x86_64 0:5.1.5-1.el7.remi 依存性関連をインストールしました: php70-php-pecl-apcu-bc.x86_64 0:1.0.3-1.el7.remi 完了しました! |
APCuの設定ファイルが/etc/opt/remi/php70/php.d/40-apcu.iniにあるのでこれを利用します。
1 |
# cp /etc/opt/remi/php70/php.d/40-apcu.ini /etc/php.d/ |
40-apcu.ini のextension=を変更します。
これ以外の項目は必要に応じて変更して下さい。
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 61 62 63 64 65 |
# vi /etc/php.d/40-apcu.ini # cat /etc/php.d/40-apcu.ini ; Enable APCu extension module extension = /opt/remi/php70/root/usr/lib64/php/modules/apcu.so ; This can be set to 0 to disable APCu apc.enabled=1 ; Setting this enables APCu for the CLI version of PHP ; (Mostly for testing and debugging). ;apc.enable_cli=0 ; Sets the path to text files containing caches to load from disk upon ; initialization of APCu. preload_path should be a directory where each ; file follows $key.data where $key should be used as the entry name ; and the contents of the file contains serialized data to use as the value ; of the entry. ;apc.preload_path= ; The size of each shared memory segment, with M/G suffixe ;apc.shm_size=32M ; The number of seconds a cache entry is allowed to idle in a slot in case ; this cache entry slot is needed by another entry. ;apc.ttl=0 ; The number of seconds that a cache entry may remain on the ; garbage-collection list. ;apc.gc_ttl=3600 ; If you begin to get low on resources, an expunge of the cache ; is performed if it is less than half full. This is not always ; a suitable way of determining if an expunge of the cache ; should be per apc.smart allows you to set a runtime configuration ; value which is used to determine if an expunge should be run ; if (available_size < apc.smart * requested_size) ;apc.smart=0 ; A "hint" about the number variables expected in the cache. ; Set to zero or omit if you are not sure; ;apc.entries_hint=4096 ; The mktemp-style file_mask to pass to the mmap module apc.mmap_file_mask=/tmp/apc.XXXXXX ; On very busy servers whenever you start the server or ; modify files you can create a race of many processes ; all trying to cache the same data at the same time. ; By default, APCu attempts to prevent "slamming" of a key. ; A key is considered "slammed" if it was the last key set, ; and a context other than the current one set it ( ie. it ; was set by another process or thread ) ;apc.slam_defense=1 ; Defines which serializer should be used ; Default is the standard PHP serializer. ;apc.serializer='default' ; use the SAPI request start time for TTL ;apc.use_request_time=1 ; Enables APCu handling of signals, such as SIGSEGV, that write core files ; when signaled. APCu will attempt to unmap the shared memory segment in ; order to exclude it from the core file ;apc.coredump_unmap=0 |
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 |
# php -v PHP 7.0.8 (cli) (built: Jun 22 2016 11:57:34) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.8, Copyright (c) 1999-2016, by Zend Technologies # php -i | egrep 'apc|opcache' Additional .ini files parsed => /etc/php.d/10-opcache.ini, /etc/php.d/40-apcu.ini, apcu MMAP File Mask => /tmp/apc.XXXXXX apc.coredump_unmap => Off => Off apc.enable_cli => Off => Off apc.enabled => On => On apc.entries_hint => 4096 => 4096 apc.gc_ttl => 3600 => 3600 apc.mmap_file_mask => /tmp/apc.XXXXXX => /tmp/apc.XXXXXX apc.preload_path => no value => no value apc.serializer => php => php apc.shm_segments => 1 => 1 apc.shm_size => 32M => 32M apc.slam_defense => On => On apc.smart => 0 => 0 apc.ttl => 0 => 0 apc.use_request_time => On => On apc.writable => /tmp => /tmp opcache.blacklist_filename => /etc/opt/remi/php70/php.d/opcache*.blacklist => /etc/opt/remi/php70/php.d/opcache*.blacklist opcache.consistency_checks => 0 => 0 opcache.dups_fix => Off => Off opcache.enable => On => On opcache.enable_cli => Off => Off opcache.enable_file_override => Off => Off opcache.error_log => no value => no value opcache.fast_shutdown => 0 => 0 opcache.file_cache => no value => no value opcache.file_cache_consistency_checks => 1 => 1 opcache.file_cache_only => 0 => 0 opcache.file_update_protection => 2 => 2 opcache.force_restart_timeout => 180 => 180 opcache.huge_code_pages => On => On opcache.inherited_hack => On => On opcache.interned_strings_buffer => 8 => 8 opcache.lockfile_path => /tmp => /tmp 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 => 2 => 2 opcache.revalidate_path => Off => Off opcache.save_comments => 1 => 1 opcache.use_cwd => On => On opcache.validate_timestamps => On => On |
1 |
# apachectl restart |