Title: Running plugin without shell_exec
Last modified: August 6, 2026

---

# Running plugin without shell_exec

 *  [kulacs1](https://wordpress.org/support/users/kulacs1/)
 * (@kulacs1)
 * [2 days, 22 hours ago](https://wordpress.org/support/topic/running-plugin-without-shell_exec/)
 * 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:
 *     ```wp-block-code
       --- 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](https://wordpress.org/support/users/dvershinin/)
 * (@dvershinin)
 * [2 days, 20 hours ago](https://wordpress.org/support/topic/running-plugin-without-shell_exec/#post-18985884)
 * Hi [@kulacs1](https://wordpress.org/support/users/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frunning-plugin-without-shell_exec%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/opcache-reset/assets/icon.svg?rev=3419574)
 * [OPcache Reset](https://wordpress.org/plugins/opcache-reset/)
 * [Support Threads](https://wordpress.org/support/plugin/opcache-reset/)
 * [Active Topics](https://wordpress.org/support/plugin/opcache-reset/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/opcache-reset/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/opcache-reset/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Danila Vershinin](https://wordpress.org/support/users/dvershinin/)
 * Last activity: [2 days, 20 hours ago](https://wordpress.org/support/topic/running-plugin-without-shell_exec/#post-18985884)
 * Status: not resolved