Learn about Centmin Mod LEMP Stack today
Register Now

PHP-FPM How to Force Updating/Reload Page Web (cache)?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by chorong91, Aug 8, 2016.

  1. chorong91

    chorong91 New Member

    16
    2
    3
    Dec 1, 2015
    Ratings:
    +2
    Local Time:
    7:11 PM
    I had some website.. most of them using laravel..
    I need to know..
    How can I force update/reload when I change file/data on a website?
    I usually using git for update my project file..
    everytime I am git push some file..
    even if I already check that file already change on server..
    But It still not change on website.. maybe because cache?
    and I need to "nprestart" for website instantly change..
    What must I do so I can force a website reload/update cache?
    Or can I disabled this cache?
    can I just disable cache for just some website?
     
  2. RoldanLT

    RoldanLT Well-Known Member

    3,901
    949
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,298
    Local Time:
    5:11 PM
    1.11
    10.2
    Disable Zend Opcache or make it reload every 5 seconds..
     
  3. Sunka

    Sunka Active Member

    917
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +388
    Local Time:
    11:11 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    Mine is set to 180 seconds.
    What is your configuration in zendopcache.ini file? @RoldanLT, @eva2000, anybody else...

    Code:
    zend_extension=opcache.so
    ;opcache.error_log=/var/log/php_opcache_error.log
    opcache.enable=1
    opcache.memory_consumption=256
    opcache.interned_strings_buffer=8
    opcache.max_wasted_percentage=5
    opcache.max_accelerated_files=16000
    ; http://php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
    ; defaults to zend opcache checking every 180 seconds for PHP file changes
    ; set to zero to check every second if you are doing alot of frequent
    ; php file edits/developer work
    ; opcache.revalidate_freq=0
    opcache.revalidate_freq=180
    opcache.fast_shutdown=0
    opcache.enable_cli=0
    opcache.save_comments=1
    opcache.enable_file_override=1
    opcache.validate_timestamps=1
    opcache.huge_code_pages=0
     
    • Like Like x 1
  4. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    7:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    If the file is php then yes caching could be Zend Opcache related, the default revalidate frequency is 180 seconds
    Code (Text):
    php --ri 'Zend OPcache'
    
    Zend OPcache
    
    Opcode Caching => Disabled
    Optimization => Disabled
    SHM Cache => Enabled
    File Cache => Disabled
    Startup Failed => Opcode Caching is disabled for CLI
    
    Directive => Local Value => Master Value
    opcache.enable => On => On
    opcache.use_cwd => On => On
    opcache.validate_timestamps => On => On
    opcache.inherited_hack => On => On
    opcache.dups_fix => Off => Off
    opcache.revalidate_path => Off => Off
    opcache.log_verbosity_level => 1 => 1
    opcache.memory_consumption => 64 => 64
    opcache.interned_strings_buffer => 8 => 8
    opcache.max_accelerated_files => 8000 => 8000
    opcache.max_wasted_percentage => 5 => 5
    opcache.consistency_checks => 0 => 0
    opcache.force_restart_timeout => 180 => 180
    opcache.revalidate_freq => 180 => 180
    opcache.file_update_protection => 2 => 2
    opcache.preferred_memory_model => no value => no value
    opcache.blacklist_filename => no value => no value
    opcache.max_file_size => 0 => 0
    opcache.protect_memory => 0 => 0
    opcache.save_comments => 1 => 1
    opcache.fast_shutdown => 1 => 1
    opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
    opcache.enable_file_override => On => On
    opcache.enable_cli => Off => Off
    opcache.error_log => no value => no value
    opcache.restrict_api => no value => no value
    opcache.lockfile_path => /tmp => /tmp
    opcache.file_cache => no value => no value
    opcache.file_cache_only => 0 => 0
    opcache.file_cache_consistency_checks => 1 => 1
    opcache.huge_code_pages => Off => Off


    You can exclude a file or path from Zend Opcache caching completely via blacklist option too
    To customise Zend Opcache settings see the instructions to create your own .ini settings file to retain the changes at https://centminmod.com/phpfpm.html#customphpini

    Example order of php .ini files applied via php --ini command
    Code (Text):
    php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: /etc/centminmod/php.d
    Additional .ini files parsed:      /etc/centminmod/php.d/a_customphp.ini,
    /etc/centminmod/php.d/curlcainfo.ini,
    /etc/centminmod/php.d/geoip.ini,
    /etc/centminmod/php.d/igbinary.ini,
    /etc/centminmod/php.d/imagick.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/zendopcache.ini

    If i want to override opcache.revalidate_freq 180 seconds default, I'd create a .ini file after /etc/centminmod/php.d/zendopcache.ini alphabetically i.e. /etc/centminmod/php.d/zzendopcache.ini

    So ordered after zendopcache.ini
    Code (Text):
    php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: /etc/centminmod/php.d
    Additional .ini files parsed:      /etc/centminmod/php.d/a_customphp.ini,
    /etc/centminmod/php.d/curlcainfo.ini,
    /etc/centminmod/php.d/geoip.ini,
    /etc/centminmod/php.d/igbinary.ini,
    /etc/centminmod/php.d/imagick.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/zendopcache.ini,
    /etc/centminmod/php.d/zzendopcache.ini


    In /etc/centminmod/php.d/zzendopcache.ini add value say 10 seconds
    Code (Text):
    opcache.revalidate_freq = 10


    Note though reducing revalidation frequency lowers performance of caching all the time 24/7. Best way is just to restart php-fpm and nginx after file updates which are done manually via command shortcut
    Code (Text):
    nprestart

    After restart recheck value is now at 10 seconds
    Code (Text):
    php --ri 'Zend OPcache'
    
    Zend OPcache
    
    Opcode Caching => Disabled
    Optimization => Disabled
    SHM Cache => Enabled
    File Cache => Disabled
    Startup Failed => Opcode Caching is disabled for CLI
    
    Directive => Local Value => Master Value
    opcache.enable => On => On
    opcache.use_cwd => On => On
    opcache.validate_timestamps => On => On
    opcache.inherited_hack => On => On
    opcache.dups_fix => Off => Off
    opcache.revalidate_path => Off => Off
    opcache.log_verbosity_level => 1 => 1
    opcache.memory_consumption => 64 => 64
    opcache.interned_strings_buffer => 8 => 8
    opcache.max_accelerated_files => 8000 => 8000
    opcache.max_wasted_percentage => 5 => 5
    opcache.consistency_checks => 0 => 0
    opcache.force_restart_timeout => 180 => 180
    opcache.revalidate_freq => 10 => 10
    opcache.file_update_protection => 2 => 2
    opcache.preferred_memory_model => no value => no value
    opcache.blacklist_filename => no value => no value
    opcache.max_file_size => 0 => 0
    opcache.protect_memory => 0 => 0
    opcache.save_comments => 1 => 1
    opcache.fast_shutdown => 1 => 1
    opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
    opcache.enable_file_override => On => On
    opcache.enable_cli => Off => Off
    opcache.error_log => no value => no value
    opcache.restrict_api => no value => no value
    opcache.lockfile_path => /tmp => /tmp
    opcache.file_cache => no value => no value
    opcache.file_cache_only => 0 => 0
    opcache.file_cache_consistency_checks => 1 => 1
    opcache.huge_code_pages => Off => Off

    Any php related setting can override and customised this way as well :)
     
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    7:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    script your git updates on server via shell script easy

    i.e. create a file like gitupdate.sh add to it
    Code (Text):
    #!/bin/bash
    cd /gitdirectory
    git pull
    nprestart

    then make it executable
    Code (Text):
    chmod +x gitupdate.sh

    run it
    Code (Text):
    ./gitupdate.sh
     
    Last edited: Aug 8, 2016
    • Like Like x 1
  6. Sunka

    Sunka Active Member

    917
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +388
    Local Time:
    11:11 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    Uh, I look at my actual (on server) /etc/centminmod/php.d/zendopcache.ini and see that opcache.revalidate_freq was changed to default (180) from my custom (30).
    Is that done with php upgrade or something else?

    I changed value now through customphp.ini file, execute nprestart and now value is show 30.
    Will be interesting after next php update, will be opcache.revalidate_freq value stay to 30 or be back to 180
     
  7. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    7:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    That zendopcache.ini will be overridden. For custom php settings read centminmod.com/phpfpm.html#customphpini. You might want to create /etc/centminmod/php.d/zzendopcache.ini to override centmin mod defaults at /etc/centminmod/php.d/zendopcache.ini and restart PHP-FPM. The files are ordered by alphanumerically from output of command

    Code (Text):
    php --ini
    

    Code (Text):
    php --ini
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: /etc/centminmod/php.d
    Additional .ini files parsed:      /etc/centminmod/php.d/a_customphp.ini,
    /etc/centminmod/php.d/curlcainfo.ini,
    /etc/centminmod/php.d/geoip.ini,
    /etc/centminmod/php.d/igbinary.ini,
    /etc/centminmod/php.d/imagick.ini,
    /etc/centminmod/php.d/mailparse.ini,
    /etc/centminmod/php.d/memcache.ini,
    /etc/centminmod/php.d/memcached.ini,
    /etc/centminmod/php.d/redis.ini,
    /etc/centminmod/php.d/zendopcache.ini,
    /etc/centminmod/php.d/zzendopcache.ini
    

    so /etc/centminmod/php.d/zzendopcache.ini comes after /etc/centminmod/php.d/zendopcache.ini to override settings in /etc/centminmod/php.d/zendopcache.ini

    Also outlined in Getting Started Guide Step 17
     
    • Like Like x 1