PHP’s Zend Opcache Config & Web Viewer

PHP 5.5. has zend opcache support in core. Since APC is not updated from long time, we made a switch to new Zend Opcache. Below is our config and web-based stats viewer.

PHP’s Zend Opcache Config

In your php.ini or depending on your PHP version

/etc/php5/fpm/conf.d/05-opcache.ini

or /etc/php/7.0/mods-available/opcache.ini

zend_extension=opcache.so
opcache.memory_consumption=512
opcache.max_accelerated_files=50000

;following can be commented for production server
opcache.revalidate_freq=0
opcache.consistency_checks=1

Web Viewer

Unlike APC, for Zend Opcache there are plenty of web-based viewer. May be reason being zend opcache’s official status has something to do with it. Below is list to choose from.

#1. Opcache-Status by Rasmus Lerdorf

This is by PHP creator himself. Very beautiful.

Installation

cd /var/www/example.com/htdocs
wget https://raw.github.com/rlerdorf/opcache-status/master/opcache.php

Screenshot:

rlerdorf-opcache-status

#2. opcache-gui by amnuts

Responsive. Feature-rich. Notably option to enable real-time stats and and option to reset/flush opcache.

If you are going to use this, make sure it is protected by some security layer.

Installation:

cd /var/www/example.com/htdocs/
wget https://raw.github.com/amnuts/opcache-gui/master/index.php -O op.php

Screenshot:

amnuts-opcache-gui

#3. ocp.php by ck-on

Has best way to analyse/explore file-based cache. UI is more old-style.

Installation:

wget https://gist.github.com/ck-on/4959032/raw/0b871b345fd6cfcd6d2be030c1f33d1ad6a475cb/ocp.php

Screenshot:

ck-Opcache-Control-Panel

We are using all 3 for now! We will update this post if we add or remove anything from our list.

Comments

  1. Spazl Avatar

    Hi i really like your tests on php5.5 wish my shared hosti g had it installed. As well be able to use wordpress with memcached setup to really have a performance boost even tough shared hosting with a cdn setup is really fast.

    1. Rahul Bansal Avatar

      Why wish when you can get VPS with SSD at $5/month from https://www.digitalocean.com/pricing

      CDN only helps offloading static content. Nginx, PHP & VPS can speed-up entire site at many different levels.

      1. Spazl Avatar

        Question is if the vps is a shared vps and used up resources hhow ever memcached option be nice

      2. Michael Nordmeyer Avatar

        It’s a KVM based VPS which means you’re getting guaranteed resources. I’m testing the smallest Digital Ocean VPS right now.

        If you want to know what could be missing try Digital Ocean’s UserVoice to see what other people are missing.

      3. Rahul Bansal Avatar

        @Spazl Here is link – https://digitalocean.uservoice.com/ @Michael is talking about.

  2. Martin Avatar

    It’s actually wise to use one of these web based viewers so you can better adjust cache values, depending on your configuration. I like the live feed of the opcache-gui by amnuts, myself

    1. Rahul Bansal Avatar

      Yep. I check stats pages like per week.

      If I see free memory going below 10MB, I increase RAM allocation.

      1. Martin Avatar

        What’s happens to things if memory is exhausted though?
        Is there a similar tuning script for memcached as well, that you know of?

      2. Rahul Bansal Avatar

        @Martin Any kind of caching mechanism starts flushing cached entries as soon as storage limit is reached.

        Please check our memcache config here – https://rtcamp.com/tutorials/php/memcache/

        @Michael Agree with you. I am more concerned about hit rate. About RAM, I try to give away as much as possible to caches.

      3. Michael Nordmeyer Avatar

        I’d rather look at the hit rate. Depending on your site’s content you’ll come to a point where the cacheable amount of data is larger than your server’s memory.

  3. Martin Avatar

    An interesting set of observations between APC and Zend Opcache which suggests Opcache is a memory hog and not as effective as APC. Just thought I’d go digging a bit

    1. Rahul Bansal Avatar

      How did you conclude that? APC also caches user data by the way. So make sure you are not using APC user-cache while running any benchmarks.

    2. Michael Nordmeyer Avatar

      The problem with APC and it’s user cache is that the cache is created n times for n PHP processes like php-fpm or Apache process. If you want to scale you need lots of processes to serve the increasing amount of users. That’s why one cache (e.g. memcache) for n PHP processes is more economically.

      1. Rahul Bansal Avatar

        I think Martin is comparing APC’s opcocde caching feature v/s PHP’s new built-in zend opcode cache in terms of memory.

  4. lorenzo noccioli Avatar

    i tried most of caching tool to increase my site performance (and reduce my server load) but i wasn’t able to find anything “good”, i have a vps with some site on it (wordpress, custom made cms, and so) and no caching system was good, lastly i tried zend opcache, and it made the load of server dramatically drop, but some thing in wordpress were broken (jetpack stats for example) and a “hand made” site loaded partially and become useless (i guess it is something about ajax, but i have no idea on where to check)… so i reverted, and that is really a pity, because using opcache it was all so fast and i have a real unloaded server…

    1. Rahul Bansal Avatar

      Jetpack breaking is unexpected.

      Did you try?

      opcache.revalidate_freq=0
      opcache.consistency_checks=1

      For non-logged in users, if your PHP app is on Nginx, try fastcgi-cache – https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/

  5. popEating Avatar

    thank you rahul,
    i tried your suggestion, but all the wp-admin site become useless (page unavailable) with opcache installed, and some other site i host arent working properly; it’s really a pity beacuse on fronte end side, opcache really speed up!

    1. Rahul Bansal Avatar

      I am really clueless. This and every site we are running is using PHP Zend Opcache.

      Do you have any ioncube encrypted plugin?

  6. popEating Avatar

    Following your instructions, i updated to php 5.5 and i managed to have this:
    PHP 5.5.9-1+sury.org~precise+1 (cli) (built: Feb 13 2014 15:53:53)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

    thank you thank you thank you

  7. Charlie Pryor Avatar

    I’m a bit confused here… how to I put some security on these pages? I don’t need everyone being able to see them. How do I limit access to just me, like I did with phpmyadmin?

    Also… after installing easyengine and using it… I love it. Thanks you guys. One problem I have though is that WordPress now asks over and over again for FTP settings in order to do anything for me. I have to change W3TC settings manually (it warns me to make changes), and WordPress themes and plugins will not update without that information.

    I figured this easy-to-install package wouldn’t have that issue. It does likely have to do with the fact that I imported my old database from my other host into this site. How do I fix it?

    1. Charlie Pryor Avatar

      Also, as an added note… It looks like my RAM is at 100% usage. How can I stop that from happening? I have only 1GB of RAM on the server, and I have the “ideal” cache settings in W3 (using memcache). Am I simply under-powered, or is my settings messed up? It’s the $10 box at Digital Ocean.

      1. Rahul Bansal Avatar

        If you are seeing 100% usage in Zend Opcache, simply increase it’s size.

        What is your current size?

    2. Rahul Bansal Avatar

      You can use HTTP AUTH to protect these pages. If you are using EasyEngine, then these pages must be under `/ee` which is already protected location.

      For all file-transfer purpose, you should use `www-data` user (if following my tutorials). Make sure you chown all files under `/var/www` to `www-data` user/group so your FTP issue might get fixed.

      cd /var/www 
      chown -R www-data: /var/www 

      Then for SFTP…

      passwd www-data

      Set a password for www-data and use that user over SFTP (not normal FTP).

      1. Charlie Pryor Avatar

        Not for file transfer purposes. I mean, when I visit http://pryormedia.net/opcache.php – I can see it. It’s publicly viewable. I’m sorry to ask this, as I’m sure it’s like Linux 101 stuff… but what can I do to password protect this viewing/page? Restrict it to a username and password. What are the steps I can take? I know they are probably simple, but I don’t know the linux commands to use. Thank you for your time.

      2. Rahul Bansal Avatar

        You can use HTTP Auth from webserver to protect any URL at server level.

  8. Lance Avatar
    Lance

    I refered to your article before actually having our server used opcache. We now have one, and phpinfo indicates that its up and running, but its not actually caching anything. Aside from the default config, I only edited minimum config variables as suggested in the recommended settings: http://www.php.net/manual/en/opcache.installation.php

    Someone at stackoverflow has the same problem, but noone is answering. The server is mint, PHP has just been upgraded from 5.4 to 5.5.10. Where do you think I should start looking to fix this?

    1. Rahul Bansal Avatar

      Try using config I posted in above article. Use site for a while. Check opcache stats again from webserver.

      You should see cache usage. If not, there could be some issue with php-build as config part is very small.

      I am not sure how did you install php, but if you are using wordpress and nginx – try https://rtcamp.com/easyengine . PHP it installs definiely have zend opcache cache working.

Book a strategy call
with our experts

No obligation. Limited slots.

Contact Form Business Enquiry

"*" indicates required fields

Please attach any RFP, project specification, or document that you would like to share.
Drop files here or
Max. file size: 5 GB.
    This field is for validation purposes and should be left unchanged.