Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.5 OPCache not working on apache

I'm in charge of the opcode cache exchange here in my company, we're moving from eaccelerator to the Zend OPCache shipped with PHP 5.5.

When I access PHP in CLI, it seems like the OPCache is working fine:

PHP 5.5.5 (cli) (built: Oct 15 2013 10:29:13)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

But when I access my website via Apache, the benchmarks show no improvements compared to the same pages using no opcode cache. Also, get_loaded_extensions(true) returns an empty array.

Can anyone answer me why on earth it isn't working?

I'm using windows 7, Apache 2.4.6 from Apache Lounge, PHP 5.5.5 from windows.php.net.


EDIT:

As requested, my OPCache configuration:

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
;opcache.validate_timestamps=1
opcache.revalidate_freq=60
;opcache.revalidate_path=0
;opcache.save_comments=1
;opcache.load_comments=1
opcache.fast_shutdown=1
;opcache.enable_file_override=0
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
;opcache.blacklist_filename=
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
;opcache.error_log=
;opcache.log_verbosity_level=1
;opcache.preferred_memory_model=
;opcache.protect_memory=0
like image 511
Denis Lins Avatar asked Oct 21 '13 13:10

Denis Lins


People also ask

How do I enable OPcache in PHP?

OPcache can only be compiled as a shared extension. If you have disabled the building of default extensions with --disable-all, you must compile PHP with the --enable-opcache option for OPcache to be available. Once compiled, you can use the zend_extension configuration directive to load the OPcache extension into PHP.

How can I tell if Zend OPcache is working?

To check if the caching engine works properly, just look at the percentages at the “Overview” tab at the opcache-gui page. If the memory usage and hit rate values are greater than zero, it means that the OpCache is caching the PHP code and the cached files are being used to handle the requests.

When should I purge my OPcache?

8. If your server has PHP 5.5 or higher, you will see an in the admin bar to Purge OPcache. You can read on the PHP manual to know more about OPcache: OPCache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.


2 Answers

Found the answer!

zend_extension extensions must set the complete path, not a relative one.

In this case, zend_extension="C:\Apache24\php\ext\php_opcache.dll" solved my problems.

like image 79
Denis Lins Avatar answered Oct 09 '22 22:10

Denis Lins


WINDOWS PHP 7 SOLUTION

By default there are opcache settings in php.ini files like opcache.eneable but enabling opcache does not take effect unless you add:

zend_extension=php_opcache.dll

to your config file. Remember it is zend_extension and not regular exstension !

like image 38
BIOHAZARD Avatar answered Oct 09 '22 23:10

BIOHAZARD