インストール手順

OPcache は共有ライブラリ形式の拡張モジュールとしてしかコンパイルできません。 --disable-all を指定してデフォルトでコンパイルされる拡張モジュールを無効にしている場合は、OPcache が利用可能になるように --enable-opcache オプションを使って PHP をコンパイルしなければいけません。

いったんコンパイルすると、zend_extension 設定ディレクティブを使って OPcache を PHP にロードできます。これは zend_extension=/full/path/to/opcache.so という設定で行えます。Windows の場合は zend_extension=C:\path\to\php_opcache.dll を使います。

注意:

OPcache を » Xdebug と一緒に使う場合は、OPcache を Xdebug より前にロードさせなければいけません。

推奨される php.ini の設定

良好なパフォーマンスを得るために、一般的に推奨される設定は次の通りです。

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1 ; PHP 7.2.0 より前のバージョンで有効
opcache.enable_cli=1

opcache.save_comments を無効にし、 opcache.enable_file_override を有効にしたいと思うかもしれませんが、この設定を行う前に実運用環境であなたのコードを必ずテストするようにしてください。なぜなら、この設定は特にドキュメント向けのコメントやアノテーションを使っている場合に、既存のフレームワークやアプリケーションが壊れることが既知の現象としてあるからです。

Windows では、 opcache.file_cache_fallback を有効にすべきです。 かつ、既に存在し、書き込み可能なディレクトリを opcache.file_cache に設定すべきです。

OPcache がサポートしている設定ディレクティブの完全なリストは 実行時設定 のページにあります。

add a note

User Contributed Notes 2 notes

up
37
NoiseEee
10 years ago
While the "suggested" opcache settings for php.ini might be appropriate for a production server, you're going to want to change several while you're developing, or you're not going to see any changes to your code. Get familiar with what they mean before blindly pasting that into php.ini and assuming things are going to work well.
up
20
stchr
3 years ago
Please note that opcache.fast_shutdown was removed in PHP 7.2
To Top