- 🇧🇪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
- For some unknown reason,
Drupal::httpClient()
didn't work for me and I had to go withcurl
- 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 - 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
- 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
- Create a controller with a static method which calls the