Use a PHP code cache for newer PHP versions

If you're using PHP 5.5 or later, there is one simple way you can double the speed of your server, and that is to enable the Zend OPcache extension - it is fast, free, and ships as standard in all new versions of PHP. Previously there were other options, such as the Alternative PHP Cache (APC), but OPcache is now the standard and it's excellent – there's no reason to use anything else for most scenarios.

To enable OPcache, make sure this is set in your php.ini file: opcache.enable=1. You'll need to restart your server to have that setting take effect, and it's worth using phpinfo() to verify that it's enabled correctly. Note that some configurations of OPcache mean that any changes you make to a script won't take affect for a period of time, sometimes up to a minute. This is there to maximise performance, but may be a bit confusing at first!

 

Next chapter: Read the manual carefully >>

Previous chapter: Use the Zend Optimizer for older PHP versions

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.