HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/KLeeuwen/samenbouwen.in/wwwroot/wp-content/mu-plugin/clear-php-opcode-caches.php
<?php
/**
 * Plugin Name: Clear PHP opcode caches
 * Plugin URI: https://www.saotn.org/wordpress-plugin-flush-php-opcache/
 * Donate Link: https://www.paypal.me/jreilink
 * Description: Clears out various PHP opcode and user caches. Currently it tries to clear, or flush, PHP OPcache and WinCache caches from memory. Easily extended to flush Redis, Memcached, and APCu cache. This should ease WordPress updates and plugin activation / deactivation.
 * Network: True
 * Version: 1.0
 * Author: Jan Reilink
 * Author URI: https://www.saotn.org
 * License: GPLv2
 */

function clear_iis_wincache() {
	if( ! function_exists( 'wincache_ucache_get' ) ) {
		return;
	}
	if( ! wincache_ucache_clear() ) {
		return false;
	}
	else {
		return true;
	}
}

function clear_php_opcache() {
	if( ! extension_loaded( 'Zend OPcache' ) ) {
		return;
	}
	$opcache_status = opcache_get_status();
	if( false === $opcache_status["opcache_enabled"] ) {
		// extension loaded but OPcache not enabled
		return;
	}
	if( ! opcache_reset() ) { 
		return false;
	}
	else {
		/**
		 * opcache_reset() is performed, now try to clear the 
		 * file cache.
		 * Please note: http://stackoverflow.com/a/23587079/1297898
		 *   "Opcache does not evict invalid items from memory - they 
		 *   stay there until the pool is full at which point the 
		 *   memory is completely cleared"
		 */
		foreach( $opcache_status['scripts'] as $key => $data ) {
			$dirs[dirname( $key )][basename( $key )] = $data;
			opcache_invalidate( $data['full_path'] , $force = true );
		}
		return true;
	}
}

function clear_caches() {
	if ( clear_iis_wincache() ) {
		error_log( 'WinCache user cache cleared.' );
	}
	else {
		error_log( 'Clearing WinCache user cache opcode cache failed.' );
	}
	if( clear_php_opcache() ) {
		error_log( 'PHP OPcache opcode cache cleared.' );
	}
	else {
		error_log( 'Clearing PHP OPcache opcode cache failed.' );
	}
}
add_filter( 'upgrader_pre_install', 'clear_caches', 10, 2 );
?>