PHP's OPcache and Drupal

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Garrett Albright's picture

The recently released PHP 5.5 introduces a built-in opcode cache solution called, well, OPcache. The same system is also available for some earlier versions of PHP via PECL. The fact that it is shipped with and developed alongside the PHP core means that there shouldn't be any problems in the future with the PHP core introducing functionality that the opcode cache can't handle, as can be the case with third-party systems. Here's a nice summary of the system, and here's the docs on PHP.net.

Has anyone experimented with this system and D7 or D8 yet? Any reports? It certainly looks promising, and the configuration looks very simple.

Comments

OPcache is faster than APC

FluxSauce's picture

Hi,

I did some benchmarking when I was writing http://www.lynda.com/PHP-tutorials/PHP-55-First-Look/124072-2.html - in the course, I used WordPress (simplicity of demoing), but when I was writing it I used Drupal 7 and a couple other frameworks.

I used https://github.com/c9s/phpbrew to compile PHP 5.5. You can also compile OPcache separately with PHP 5.3 and above if my memory serves from the PHP 5.5 sources.

I didn't save the benchmarks, but as I recall there was at least a 10% speedup compared to APC.

I haven't tried 5.5 yet (on

Jamie Holly's picture

I haven't tried 5.5 yet (on the todo list this week - get it built), but the opcode cache in 5.5 is basically the Zend OPcode cache. From experiences on 5.2 and 5.3, it does run around 10% faster than APC. There are some minor "gotchas" though, like when installing Symfony, it doesn't recognize Zend (that may be fixed now).

As far as D7, it runs fine in Zend. Never had a problem from it or numerous different contrib modules I tried. Now as far as code running in 5.5, I'm not sure. Of course the code changes from 5.4 to 5.5 are so minimal I haven't seen anything that would affect Drupal or even a majority of Contrib. If there's any problems then they most likely exist with 5.4 as well.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

I just tried to install D7

haggins's picture

I just tried to install D7 into a jelastic environment with php 5.5 + opcache enabled, but I'm stuck at the database configuration page. It creates 31 tables and then refreshes the page asking for database credentials again.
Unfortunately the apache error log is empty.

As soon as I disable opcache everything works fine.

Well, that's not promising.

Garrett Albright's picture

Well, that's not promising. =/ Have you considered creating an issue in the Drupal project queue about that?

This is due to this 3year old

dalin's picture

This is due to this 3year old bug:
https://drupal.org/node/779482
there's a patch there that probably needs to be re-rolled.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

I'm curious how you disabled

dagomar's picture

I'm curious how you disabled the OPCache?

[EDIT]
Found it, in my setup (ubuntu 13:10), I found:
/etc/php5/apache2/conf.d/05-opcache.ini

Inside that I did this:

; configuration for php ZendOpcache module
; priority=05
; zend_extension=opcache.so

I hope that doesn't destroy anything, but for my setup it seems to work fine.

Opcache

edvanleeuwen's picture

I am using OpCache with D7 for some time now and it has very much increased performance. This is both with anynomous access as well as authenticated.

Alauddin's picture

https://www.drupal.org/node/779482

Looks like we need opcache turned off during drupal install..but otherwise seems to work fine.

Here is possible temp solutions to get drupal to install.

If PHP runs as Apache module (mod_php), use an .htaccess file:

php_flag opcache.enable Off

If PHP runs as CGI/FastCGI, use php.ini:
opcache.enable=0

@see https://www.drupal.org/n

dalin's picture

@see
https://www.drupal.org/node/779482
Committed to D8, needs a back-port to D7/D6.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

Drupal 7 OPcache Configuration

mahyarsbt's picture

Hi,

I installed Drupal 7 on ubuntu 14.04.3 LTS with:
Nginx 1.9.6
PHP 5.5.30 (cli)
Mysql 5.5.45
Varnish 4.1.0
Redis 3.0.5

I need to know what is best opcache configuration for drupal 7.

Do i need to add anything to settings.php?

This is my opcache configuration in php.ini

[opcache]
zend_extension=opcache.so

; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

; The OPcache shared memory storage size.
opcache.memory_consumption=1024

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=99999

; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=5

; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1

; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
;opcache.validate_timestamps=1

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=60

; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0

; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
;opcache.save_comments=1

; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don't need them anyway.
;opcache.load_comments=1

; If enabled, a fast shutdown sequence is used for the accelerated code
opcache.fast_shutdown=1

; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0

; A bitmask, where each bit enables or disables the appropriate OPcache
; passes
;opcache.optimization_level=0xffffffff

;opcache.inherited_hack=1
;opcache.dups_fix=0

; The location of the OPcache blacklist file (wildcards allowed).
; Each OPcache blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x blacklists all the files and directories in /var/www
; that start with 'x'). Line starting with a ; are ignored (comments).
;opcache.blacklist_filename=

; Allows exclusion of large files from being cached. By default all files
; are cached.
;opcache.max_file_size=0

; Check the cache checksum each N requests.
; The default value of "0" means that the checks are disabled.
;opcache.consistency_checks=0

; How long to wait (in seconds) for a scheduled restart to begin if the cache
; is not being accessed.
;opcache.force_restart_timeout=180

; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=

; All OPcache errors go to the Web server log.
; By default, only fatal errors (level 0) or errors (level 1) are logged.
; You can also enable warnings (level 2), info messages (level 3) or
; debug messages (level 4).
;opcache.log_verbosity_level=1

; Preferred Shared Memory back-end. Leave empty and let the system decide.
;opcache.preferred_memory_model=

; Protect the shared memory from unexpected writing during script execution.
; Useful for internal debugging only.
;opcache.protect_memory=0

Thanks

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week