Reading list Switch to dark mode

    Understanding OpCache

    Updated 30 March 2019

    Hello Everyone! Today I am going to share with you all some basic information about OpCache, and how to enable it on your PHP server.

    I am preassuming that all of you know about the basic cache and it uses.

    Why Opcache?

    Basically, OpCache is a PHP extension, which when used, dramatically improves the performance of websites that use PHP. The OpCache runs out-of-the-box (by default, after installation). OPcache allows you to gain a performance boost by reducing code compilation time. When PHP code is compiled for the first time, it is saved in the server’s memory. Each time the code is called, the pre-compiled version is used instead of waiting for the code to compile, which causes a delay each time the code is used and increases the performance of the Website.

    How does it work?

    Following flowchart will help you understand the workflow of OpCache on a php website-

    opcache_working (1)

    Start your headless eCommerce
    Find out More


    How to enable OpCache?

    OpCache is generally disabled by default. In order to start using OPcache in PHP5.5+, you will first have to enable it manually. To do this you would have to do the following:

    Add the following line to your php.ini:

    zend_extension=/full/path/to/ (nix)
    zend_extension=C:\path\to\php_opcache.dll (win)

    Note that you will have to use the zend_extension directive instead of the “normal” extension directive because it affects the actual Zend engine (i.e. the thing that runs PHP).

    1. For PHP 5.4 or earlier (>= 5.2), you can install Zend OPcache using PECL.
    2. $ pecl install zendopcache-beta

    The pecl command will try to update your configure php.ini automatically.

    Now that you have setup OPcache perfectly.

    You can add the following optional settings to optimize the performance-

    1. opcache.memory_consumption=128 (for caching all compiled files)
    2. opcache.interned_strings_buffer=8
    3. opcache.max_accelerated_files=4000 (by default can cache 2000 files)
    4. opcache.revalidate_freq=60
    5. opcache.fast_shutdown=1
    6. opcache.enable_cli=1

    Is OpCache Enabled?

    To check If the OpCache is properly enabled and is working on your sever, write phpinfo(); in php file and see the status like:


    This way you can check the OpCache UP and running.

    This is all for now.

    In My next Blog, I will share more information about OpCache features, advantages, and disadvantages.

    Till then happy reading. 🙂

    . . .

    Leave a Comment

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

    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home