"Clear all caches" should also reset OpCache

Created on 11 November 2019, about 5 years ago
Updated 4 March 2024, 10 months ago

When using the UI to "clear all caches" the zend opcode cache should be cleared also.

I use git pull to deploy to production. Unfortunately sometimes, some dependencies run into error conditions. Reason is, that my opcache.revalidate_freq is 60 seconds.

I suggest to do an opcache_reset() in the "clear all caches" procedure to have that cache cleared, too.

I suggest to do an opcache_reset() ind drush cr, also. (But I never had that sync bug with drush)

I use Drupal 8.7 on CentOs 7.6 with

[proxiss@marge ~]$ php -v
PHP 7.2.20 (cli) (built: Jul  2 2019 13:37:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.20, Copyright (c) 1999-2018, by Zend Technologies
Feature request
Status

Active

Version

11.0 🔥

Component
Cache 

Last updated 3 days ago

Created by

🇩🇪Germany proxiss

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium kriboogh

    I think you could just add it to the /core/rebuild.php file, and do a curl call to that instead.
    So, modify rebuild.php like so:

      // Clear user cache for all major platforms.
      $user_caches = [
        'apcu_clear_cache',
        'wincache_ucache_clear',
      ];
    

    Should become:

      // Clear user cache for all major platforms.
      $user_caches = [
        'apcu_clear_cache',
        'wincache_ucache_clear',
        'opcache_reset',
        'apcu_clear_cache',
      ];
    

    Then drush cr can do a call to /rebuild.php.

  • 🇳🇱Netherlands nikhileshpaul Eindhoven

    Below is the approach I followed

    • Create a controller with a static method which calls the opcache_reset() function
    • Expose this static method using a custom route
    • Create a custom drush command, something like drush opcl which calls this route

    Few things I had to consider

    1. For some unknown reason, Drupal::httpClient() didn't work for me and I had to go with curl
    2. My application is behind a proxy so I had to set curl_setopt($ch, CURLOPT_PROXY, ''); for the call to local server to go through
    3. The curl call needs an absolute URL which will differ for each environment, so had to add this as a settings variable in settings.local.php
    4. For environments where the servers sit behind a load balancer, giving the load balancer/application URL didn't work. I had to manually add the web servers in the settings variable and loop through them resetting the cache. This might be an issue with cloud setups where servers are initialized on demand
Production build 0.71.5 2024