Want more timely Centmin Mod News Updates?
Become a Member

PHP-FPM Enable/Disable Zend Opcache per vhosts

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Milano, Apr 2, 2015.

  1. Milano

    Milano New Member

    15
    3
    3
    Oct 1, 2014
    Ratings:
    +3
    Local Time:
    6:31 PM
    As the title, I have a vhost for test environment and i want to disable zend opcache for this vhost. Is this possible? Or is there anyway to clear the cache via PHP.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,904
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,394
    Local Time:
    9:31 PM
    Nginx 1.13.x
    MariaDB 5.5
    Unfortunately, right now there is no out of box support for per Nginx vhost PHP opcode caching like you suggested. Only way is to create multiple PHP-FPM pools (there's only a single pool in Centmin Mod) and setup that Nginx vhost's domain.com.conf to use a new PHP-FPM pool and set in that pools' separate php-fpm.conf config file add an option for

    Code:
    php_admin_flag[opcache.enable] = off
    Probably easier to have 2 separate VPS servers one with Zend Opcache enabled and one without for long term tests.
     
    • Informative Informative x 1
  3. nVidian

    nVidian Member

    85
    8
    8
    Mar 16, 2015
    Ratings:
    +23
    Local Time:
    6:31 PM
    1.7.9
    5.5
    Yes, you can. If I'm not mistaken. This is what I do:

    1. EDIT ZENDOPCACHE.INI ( I used nano as editor, you can use any editor)
    Code:
    nano /etc/centminmod/php.d/zendopcache.ini
    
    2. ADD THIS LINE TO IT (I place it at the end of file). Of course you can place opblacklist.txt to any folder you like. I place it at cetminmod/php.d folder
    Code:
    opcache.blacklist_filename=/etc/centminmod/php.d/opblacklist.txt
    
    SO THIS IS MY ZENDOPCACHE.INI AS SAMPLE
    Code:
    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20121212/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=8000
    opcache.revalidate_freq=180
    opcache.fast_shutdown=1
    opcache.enable_cli=0
    opcache.save_comments=1
    opcache.enable_file_override=1
    opcache.validate_timestamps=1
    opcache.blacklist_filename=/etc/centminmod/php.d/opblacklist.txt
    
    3. EDIT THE OPBLACKLIST.TXT
    Code:
    nano /etc/centminmod/php.d/opblacklist.txt
    
    4. NOW TYPE THE FOLDER YOU WANT ZEND OPCACHE TO EXCLUDE
    Code:
    /home/nginx/domains/yourdomain.com/*
    
    SAVE
    RESTART PHP-FPM
    Code:
    service php-fpm restart
    
    NOW ZENDOPCACHE WILL NOT CACHE EVERYTHING IN /home/nginx/domains/yourdomain.com folder . Now you can develop your site easily without headache.


    DONT FORGET TO DELETE THAT LINE FROM OPBLACKLIST.TXT WHEN YOUR SITE IS READY FOR PRODUCTION. YOUR SITE WILL BE FASTER WITH ZEND OPCACHE CACHING.


    ALSO YES, JUST TYPE
    Code:
    service php-fpm restart
    
    And your ZendOpcache will also purge its cache

    I'M NOT AN EXPERT SO PLEASE FORGIVE & CORRECT ME IF I'M WRONG
     
    Last edited: Apr 2, 2015
    • Informative Informative x 5
    • Like Like x 1
    • Useful Useful x 1
  4. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,904
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,394
    Local Time:
    9:31 PM
    Nginx 1.13.x
    MariaDB 5.5
    ah so I was mistaken ! Thanks @nVidian (y)

    wow totally forgot about the blacklist option see PHP: Runtime Configuration - Manual

    as to clearing cache, I read that from @Milano post that he wants to clear cache from PHP file itself ? But yes restart PHP-FPM service will clear cache
     
    • Like Like x 1