* */ // common include include '/srv/http/app/config/config.php'; opcache_invalidate('/srv/http/command/cachectl.php'); // insect GET['action'] if (isset($_GET['action'])) { switch ($_GET['action']) { case 'prime': OpCacheCtl('prime', '/srv/http/', $redis); break; case 'primeall': OpCacheCtl('primeall', '/srv/http/'); break; case 'reset': OpCacheCtl('reset', '/srv/http/'); opcache_reset(); runelog('cacheCTL RESET'); echo "PHP OPCACHE CLEARED"; break; case 'debug': // opcache_reset(); echo "<pre>"; echo "OPcache status:\n"; print_r(opcache_get_status()); echo "OPcache configuration:\n"; print_r(opcache_get_configuration()); echo "</pre>"; break; } }
function OpCacheCtl($action, $basepath, $redis = null) { if ($action === 'prime' or $action === 'primeall') { $cmd = 'opcache_compile_file'; } if ($action === 'reset') { $cmd = 'opcache_invalidate'; } if ($action === 'prime') { $files = $redis->sMembers('php_opcache_prime'); foreach ($files as $file) { opcache_compile_file($file); } } if ($action === 'primeall' or $action === 'reset') { if (is_file($basepath)) { if (parseFileStr($basepath, '.') === 'php' && $basepath !== '/srv/http/command/cachectl.php') { $cmd($basepath); } } elseif (is_dir($basepath)) { $scan = glob(rtrim($basepath, '/') . '/*'); foreach ($scan as $index => $path) { OpCacheCtl($path, $action); } } } }