Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if PHP OPcache is enabled or not?

I am trying to enable opCache on my server (ubuntu 12.04 LTS, running apache 2.4.7 with PHP Version 5.5.10-1+deb.sury.org~precise+1).

Before starting to do anything, I read this highly relevant post which told me that opCache is disabled by default and I have to manually enable it.

I went into php.ini and found that there is no text with opcache.so, also everything related to opcache is commented out. Like this:

[opcache] ; Determines if Zend OPCache is enabled ;opcache.enable=0  ; Determines if Zend OPCache is enabled for the CLI version of PHP ;opcache.enable_cli=0 

This is ok, because the person told that it is disabled. But when I consult phpinfo(); it shows me the following (and based on my understanding it tells me that opCache is already used).

enter image description here

So is my opcache enabled and used and how can I see/verify it?

like image 328
Salvador Dali Avatar asked Mar 31 '14 21:03

Salvador Dali


People also ask

How can I tell if PHP Opcache is enabled?

Checking in a phpinfo. You can confirm if OPcache is functioning by creating and viewing a phpinfo. php file. View the following article for details: Creating a phpinfo.

How do I turn on Opcache?

In the SOFTWARE section of the cPanel home screen, click Select PHP Version. Select the check box next to the opcode caching extension you want to enable: If you are using PHP version 5.4 or older, select apc. If you are using PHP version 5.5 or newer, select opcache.

Should I enable Opcache?

You should definitely enable opcache. I remember that WordPress has something like 8x smaller response time with opcache. Difference may be less pronounced for Laravel, but will still be huge.

How do I use Opcache in PHP?

OPCache can only be compiled as a shared extension under this version. Firstly, you need to enable the building of default extension with –enable-opcache option to make it available. Afterwards, you can use the zend_extension configuration directive to lead the OP Cache extension into PHP.


1 Answers

Have faith in your phpinfo(), you've got the necessary shared module running or it wouldn't be showing up.

Also, your opcache is indeed enabled, but only for web, not cli. The default for the library is enabled for web so , to disable uncomment the line starting with a semicolon like this:

 opcache.enable=0  

As noted, for command line php use, the default is disabled, to enable it, uncomment and set to 1

 opcache.enable_cli=1 

Here is a list of all runtime arguments and there default value for further reference: http://www.php.net/manual/en/opcache.configuration.php

UPDATE: As of 2020, this library may be no longer maintained, see comments below for other possible options.

If you want a cool web monitor page for it (like apc.php does for apc) try this: https://github.com/rlerdorf/opcache-status

like image 188
Ray Avatar answered Sep 28 '22 03:09

Ray