{"id":1797,"date":"2014-01-10T12:42:26","date_gmt":"2014-01-10T12:42:26","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1797"},"modified":"2014-01-10T12:42:46","modified_gmt":"2014-01-10T12:42:46","slug":"using-php-5-5s-new-opcache-opcode-cache","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1797","title":{"rendered":"Using PHP 5.5&#8217;s New &#8220;OPcache&#8221; Opcode Cache"},"content":{"rendered":"<p><span style=\"line-height: 1.5;\">Zend have contributed their Zend Optimizer+ opcode cache to PHP &#8211; thanks Zend!!! (Update 19 March 2013: the renaming to &#8220;Zend OPcache&#8221; is complete)<\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<blockquote><p>&#8220;The Zend OPcache provides faster PHP execution through opcode caching and optimization.&#8221;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>The new OPcache extension can be seen as substitute for the venerable\u00a0<a href=\"http:\/\/pecl.php.net\/package\/APC\">APC cache<\/a>, the maintenance of which had become an issue. Note: although OPcache is now readily available, there is currently nothing preventing you from using any available (working!) opcode cache in PHP 5.5.<\/p>\n<p>A few minutes ago Dmitry Stogov did the physical merge to the PHP 5.5 source&#8217;s\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">ext\/opcache<\/div><\/div>\n<p>\u00a0directory. The current<a href=\"http:\/\/snaps.php.net\/\">PHP 5.5 snapshot<\/a>\u00a0has the code. Future Alpha or Beta (and Production) releases will include it too.<\/p>\n<p>Please test OPcache. It is not a panacea for all performance problems. There are a lot of settings which may need adjusting. Understanding how it works and identifying issues during the stabilization phase of PHP 5.5 release process will greatly help.<\/p>\n<p><b>To build Zend OPcache for PHP 5.5:<\/b><\/p>\n<p>When you configure PHP, add the option\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">--enable-opcache<\/div><\/div>\n<p>\u00a0like:<\/p>\n<pre>.\/configure ... --enable-opcache<\/pre>\n<p>Then\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">make<\/div><\/div>\n<p>\u00a0and\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">make install<\/div><\/div>\n<p>, as normal. This will build OPcache shared extension. It&#8217;s not possible to build it statically.<\/p>\n<p>Find the shared library in your installation directory with a command like\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">find \/home\/cjones\/php55 -name opcache.so<\/div><\/div>\n<p>Edit\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">php.ini<\/div><\/div>\n<p>\u00a0and add the extension with its full path:<\/p>\n<pre>zend_extension=\/home\/cjones\/php55\/lib\/php\/extension\/debug-non-zts-20121212\/opcache.so<\/pre>\n<p>Update (25 March 2013): Dmitry\u00a0<a href=\"http:\/\/git.php.net\/?p=php-src.git;a=commitdiff;h=0b8b6a727ddd31ff14e4af919c77a3f1b5e2b3f0\">merged a PHP 5.5 change<\/a>\u00a0so that the full path is not required for\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">zend_extension<\/div><\/div>\n<p>libraries in the\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">extension_dir<\/div><\/div>\n<p>\u00a0directory. You can now simply do\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">zend_extension=opcache.so<\/div><\/div>\n<p>.<\/p>\n<p>You&#8217;ll want to enable OPcache too:<\/p>\n<pre>opcache.enable=On<\/pre>\n<p>The\u00a0<a href=\"https:\/\/raw.github.com\/zendtech\/ZendOptimizerPlus\/master\/README\">ext\/opcache\/README<\/a>\u00a0is the current source of documentation, and lists all the other\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">php.ini<\/div><\/div>\n<p>\u00a0parameters.<\/p>\n<p>Problems can be reported in the\u00a0<a href=\"https:\/\/github.com\/zendtech\/ZendOptimizerPlus\/issues\">Github issue tracker<\/a><\/p>\n<p>Update (18 March 2013): In\u00a0<a href=\"http:\/\/git.php.net\/?p=php-src.git;a=commitdiff;h=930b272d700a7f854357628e446505fab29906a8\">a commit over the weekend<\/a>, the build option\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">--enable-opcache<\/div><\/div>\n<p>\u00a0is On by default. You will still need to update php.ini.<\/p>\n<p><b>To build Zend OPcache for older versions of PHP:<\/b><\/p>\n<p>You should be able to build OPcache with PHP 5.2 onwards<\/p>\n<p>Install it by getting the source from\u00a0<a href=\"https:\/\/github.com\/zendtech\/ZendOptimizerPlus\">Github<\/a>. There is also a\u00a0<a href=\"http:\/\/pecl.php.net\/package\/ZendOptimizerPlus\">PECL repository<\/a>; this is slightly out of date so I recommend using Github. Follow the README instructions to install it.<\/p>\n<p><b>User-data cache:<\/b><\/p>\n<p>The new opcode cache does not include a user-data cache. Joe Watkins recently started the\u00a0<a href=\"https:\/\/github.com\/krakjoe\/apcu\">APCu project<\/a>\u00a0to extract the user-data cache code from APC. Test this too!<\/p>\n<p>Update 19 March 2013: Xinchen Hui is working on a lockless user-data cache, see\u00a0<a href=\"https:\/\/github.com\/laruence\/yac\">https:\/\/github.com\/laruence\/yac<\/a>\u00a0and his blog about it\u00a0<a href=\"http:\/\/www.laruence.com\/2013\/03\/18\/2846.html\">here<\/a><a>\u00a0(in Chinese).<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Zend have contributed their Zend Optimizer+ opcode cache to PHP &#8211; thanks Zend!!! (Update 19 March 2013: the renaming to &#8220;Zend OPcache&#8221; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1797","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1797"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1797\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}