PHP 5.5 Opcache Settings

Mattias Geniar, Monday, December 8, 2014 - last modified: Monday, February 9, 2015

Unless you're running all your PHP via CLI scripts, you'll be using an Opcode Caching in your PHP configurations. This used to be APC for anything below PHP 5.5, but since PHP 5.5 there's a built-in extension called Opcode Cache that replaces APC. (note: APC is still available for user-caching, like a key/value store)

To activate the PHP Opcode Cache extension, you can drop the following lines in your /etc/php.d/ directory, to a new file named 10-opcache.ini. The reasoning behind the number in the front of the file, is to ensure this gets loaded first, before other modules.

; Enable the Opcache

; In MegaBytes, how much memory can it consume?

; The number of keys/scripts in the Opcache hash table (how many files can it cache?)

; How often to check script timestamps for updates, in seconds.
; 0 will result in OPcache checking for updates on every request.

; If enabled, OPcache will check for updated scripts every
; opcache.revalidate_freq seconds. When this directive is disabled,
; you must reset OPcache manually

; If enabled, a fast shutdown sequence is used that doesn't free
; each allocated block, but relies on the Zend Engine memory manager
; to deallocate the entire set of request variables en masse.

; Chances are, you won't need this on the CLI

; If enabled, OPcache appends the current working directory to the
; script key, thereby eliminating possible collisions between files
; with the same base name. Disabling this directive improves performance,
; but may break existing applications

Reload your PHP-FPM daemon, and you should be set. If you're looking at how your Opcache is performing, check out opcache.php (similar to apc.php's file for checking the APC performance). If you want to know more about PHP Opcode performance, make sure to read the excellent post at EngineYard on Opcode Caching.

Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *