• Hi,

    Thanks for this plugin! I’d like to use it on a hosting provider where the shell_exec function is disabled, so I’m unable to use it. I’ve created a patch that uses shell_exec only 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)
  • Plugin Author Danila Vershinin

    (@dvershinin)

    Hi @kulacs1,

    Thanks for reporting this and for the patch. I took it a step further and removed shell_exec() entirely rather than only guarding it. Version 2.4.1 is now available: file-cache cleanup uses native PHP functions, while CLI resets communicate directly with PHP-FPM over FastCGI using the existing .cachetool.yml configuration, so no CacheTool binary is needed.

    Could you update to 2.4.1 and let me know whether it works with your host’s PHP-FPM socket?

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.