Running plugin without shell_exec
-
Hi,
Thanks for this plugin! I’d like to use it on a hosting provider where the
shell_execfunction is disabled, so I’m unable to use it. I’ve created a patch that usesshell_execonly when it’s available:--- opcache-reset.php 2025-12-15 02:33:08.000000000 +0100
+++ opcache-reset.php.new 2026-08-06 11:56:54.146880433 +0200
@@ -77,8 +77,10 @@
}
if ( $file_cache_dir && file_exists( $file_cache_dir ) ) {
- // move it out of the way to avoid race conditions
- shell_exec( "mv {$file_cache_dir} {$file_cache_dir}.rm" );
+ if ( function_exists( 'shell_exec' ) ) {
+ // move it out of the way to avoid race conditions
+ shell_exec( "mv {$file_cache_dir} {$file_cache_dir}.rm" );
+ }
}
// We are in PHP-FPM context and not file cache only
@@ -87,11 +89,13 @@
}
if ( $file_cache_dir ) {
- if ( file_exists( "{$file_cache_dir}.rm" ) ) {
- shell_exec( "rm -rf {$file_cache_dir}.rm" );
+ if ( function_exists( 'shell_exec' ) ) {
+ if ( file_exists( "{$file_cache_dir}.rm" ) ) {
+ shell_exec( "rm -rf {$file_cache_dir}.rm" );
+ }
+ // make sure OPcache directory is re-created
+ shell_exec( "mkdir -p {$file_cache_dir}" );
}
- // make sure OPcache directory is re-created
- shell_exec( "mkdir -p {$file_cache_dir}" );
}
// Irrespective of the context, we should attempt to clear the memory-based OPCache, because this script may be called from CLI
@@ -105,11 +109,13 @@
}
// Try cachetool binary first.
- $cachetool = trim( shell_exec( "PATH={$path} which cachetool 2>/dev/null" ) );
- if ( $cachetool ) {
- $cmd = 'php -d opcache.enable_cli=0 -d opcache.file_cache_only=0 -d opcache.file_cache=/tmp $(which cachetool) opcache:reset';
- shell_exec( "PATH={$path} {$cmd} 2>&1" );
- return;
+ if ( function_exists( 'shell_exec' ) ) {
+ $cachetool = trim( shell_exec( "PATH={$path} which cachetool 2>/dev/null" ) );
+ if ( $cachetool ) {
+ $cmd = 'php -d opcache.enable_cli=0 -d opcache.file_cache_only=0 -d opcache.file_cache=/tmp $(which cachetool) opcache:reset';
+ shell_exec( "PATH={$path} {$cmd} 2>&1" );
+ return;
+ }
}
// Fallback: direct FastCGI if cachetool.yml exists.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.