Want to subscribe to topics you're interested in?
Become a Member

PHP-FPM Zend Opcache Validate/Revalidate Settings

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by deltahf, Feb 18, 2015.

  1. deltahf

    deltahf Active Member

    216
    104
    43
    Jun 8, 2014
    Ratings:
    +161
    Local Time:
    4:34 PM
    I just upgraded from PHP 5.3 to 5.6 and dumped APC for Zend Opcache. I really like what I'm seeing so far in terms of performance, but I'm confused about the configuration.

    First, I tried to increase the opcache.memory_consumption from the default 64 to 128, but after making this change, saving the file, and restarting PHP-FPM and Nginx it has not changed according to the GUI I'm using.

    Second, I noticed that I now have to restart PHP-FPM every single time I edit a PHP file if I want the changes to be applied. What is the best way around this, and will I be giving up any performance if I change it?
     
  2. eva2000

    eva2000 Administrator Staff Member

    31,012
    6,922
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,428
    Local Time:
    7:34 AM
    Nginx 1.13.x
    MariaDB 5.5
  3. deltahf

    deltahf Active Member

    216
    104
    43
    Jun 8, 2014
    Ratings:
    +161
    Local Time:
    4:34 PM
    Ah, thanks, I didn't see that note about the separate zendopcache.ini file. There's a big [opcache] section in /usr/local/lib/php.ini which I presumed controlled Zend Opcache:

    Code:
    [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
    
    
    ; The OPcache shared memory storage size.
    
    ;opcache.memory_consumption=128
    
    
    ; The amount of memory for interned strings in Mbytes.
    
    ;opcache.interned_strings_buffer=4
    
    
    ; The maximum number of keys (scripts) in the OPcache hash table.
    
    ; Only numbers between 200 and 100000 are allowed.
    
    ;opcache.max_accelerated_files=2000
    
    
    ; 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=2
    
    
    ; 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=0
    
    
    ; 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
    All PHP file edits require a PHP-FPM restart (or so I thought)...even a one-line "Hello world" example. I just did some research and found out why - the default opcache.validate_timestamps and opcache.revalidate_freq settings mean that Opcache will only check for changes to PHP files every 180 seconds. Sure enough, if I make an edit and wait three minutes, they do eventually show up.

    This could really drive people crazy when they switch to Opcache and I've not seen anyone else talking about this (why has nobody else noticed?), so you should probably make a note about this in the docs somewhere. I do some development on this server so I'm really going to have to re-evaluate Zend Opcache. I guess there is no way to enjoy its benefits without this delay.
     
    • Like Like x 1
  4. eva2000

    eva2000 Administrator Staff Member

    31,012
    6,922
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,428
    Local Time:
    7:34 AM
    Nginx 1.13.x
    MariaDB 5.5
    ah the zendopcache lines in /usr/local/lib/php.ini probably from PHP 5.5+ default php.ini files as i did not add those.. for Centmin Mod edit /etc/centminmod/php.d/zendopcache.ini :)

    Yeah i don't edit my PHP files much either so probably didn't hit that 180s check heh

    will have to see where to make this note though heh
     
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    31,012
    6,922
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,428
    Local Time:
    7:34 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Useful Useful x 1
  6. deltahf

    deltahf Active Member

    216
    104
    43
    Jun 8, 2014
    Ratings:
    +161
    Local Time:
    4:34 PM
    That's good. I found some more on this: Best Zend OpCache Settings/Tuning/Config

    He actually recommends turning off opcache.validate_timestamps completely and then just re-starting PHP-FPM each time you make a deployment due to a possible issue of new/old files being in the cache at the same time during large updates, but I think that's a bit extreme and impractical for how I (and probably most other Centminmod users) work on my site.

    According to these comments on StackOverflow, even if you set revalidate_freq=0, you will still get the benefits of using Opcache and it will still use the cached version of the file, there is just a little bit of additional overhead because it will have to check the date on the original file each time it is accessed.

    To see what kind of an impact this would have on my environment, I set revalidate_freq=0 for an hour and then watched the NewRelic stats to see what happened:

    Screen Shot 2015-02-18 at 5.51.09 PM.png

    I changed the setting at 5:00pm, and as you can see it had no noticeable impact on the system. I think I will leave it to around 15 or 30 seconds, then temporarily set it to 0 if I need to do some development work.

    Also, since we're looking at graphs...here's the difference between PHP 5.3 + APC and PHP 5.6 + Zend Opcache: :D

    Screen Shot 2015-02-18 at 5.55.43 PM.png
     
    • Like Like x 2
  7. eva2000

    eva2000 Administrator Staff Member

    31,012
    6,922
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,428
    Local Time:
    7:34 AM
    Nginx 1.13.x
    MariaDB 5.5
    I need a bigger and bigger LIKE button for that info.. :)

    nice use of newrelic there (y)

    when did you switch to Zend Opcache time wise on that graph ? Feb 18 12 AM ?
     
    • Friendly Friendly x 1
  8. deltahf

    deltahf Active Member

    216
    104
    43
    Jun 8, 2014
    Ratings:
    +161
    Local Time:
    4:34 PM
    Glad you found it useful. :)

    Yes, the switch to Zend Opcache can be seen at the sharp dip in the graph. Upgrading to PHP 5.6 (via Centminmod .07 script) broke the NewRelic PHP agent so I had to reinstall it, hence the 15 minutes or so there was no data sent to them.
     
  9. eva2000

    eva2000 Administrator Staff Member

    31,012
    6,922
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,428
    Local Time:
    7:34 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah same here, when you do major PHP version upgrades, you have to reinstall Newrelic PHP agent :)