{"id":18985692,"date":"2026-08-06T10:05:10","date_gmt":"2026-08-06T10:05:10","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/running-plugin-without-shell_exec\/"},"modified":"2026-08-06T10:05:10","modified_gmt":"2026-08-06T10:05:10","slug":"running-plugin-without-shell_exec","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/running-plugin-without-shell_exec\/","title":{"rendered":"Running plugin without shell_exec"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for this plugin! I&#8217;d like to use it on a hosting provider where the <code>shell_exec<\/code> function is disabled, so I&#8217;m unable to use it. I&#8217;ve created a patch that uses <code>shell_exec<\/code> only when it&#8217;s available:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>--- opcache-reset.php   2025-12-15 02:33:08.000000000 +0100<br \/>+++ opcache-reset.php.new       2026-08-06 11:56:54.146880433 +0200<br \/>@@ -77,8 +77,10 @@<br \/>        }<br \/> <br \/>        if ( $file_cache_dir &amp;&amp; file_exists( $file_cache_dir ) ) {<br \/>-               \/\/ move it out of the way to avoid race conditions<br \/>-               shell_exec( \"mv {$file_cache_dir} {$file_cache_dir}.rm\" );<br \/>+               if ( function_exists( 'shell_exec' ) ) {<br \/>+                       \/\/ move it out of the way to avoid race conditions<br \/>+                       shell_exec( \"mv {$file_cache_dir} {$file_cache_dir}.rm\" );<br \/>+               }<br \/>        }<br \/> <br \/>        \/\/ We are in PHP-FPM context and not file cache only<br \/>@@ -87,11 +89,13 @@<br \/>        }<br \/> <br \/>        if ( $file_cache_dir ) {<br \/>-               if ( file_exists( \"{$file_cache_dir}.rm\" ) ) {<br \/>-                       shell_exec( \"rm -rf {$file_cache_dir}.rm\" );<br \/>+               if ( function_exists( 'shell_exec' ) ) {<br \/>+                       if ( file_exists( \"{$file_cache_dir}.rm\" ) ) {<br \/>+                               shell_exec( \"rm -rf {$file_cache_dir}.rm\" );<br \/>+                       }<br \/>+                       \/\/ make sure OPcache directory is re-created<br \/>+                       shell_exec( \"mkdir -p {$file_cache_dir}\" );<br \/>                }<br \/>-               \/\/ make sure OPcache directory is re-created<br \/>-               shell_exec( \"mkdir -p {$file_cache_dir}\" );<br \/>        }<br \/> <br \/>        \/\/ Irrespective of the context, we should attempt to clear the memory-based OPCache, because this script may be called from CLI<br \/>@@ -105,11 +109,13 @@<br \/>        }<br \/> <br \/>        \/\/ Try cachetool binary first.<br \/>-       $cachetool = trim( shell_exec( \"PATH={$path} which cachetool 2&gt;\/dev\/null\" ) );<br \/>-       if ( $cachetool ) {<br \/>-               $cmd = 'php -d opcache.enable_cli=0 -d opcache.file_cache_only=0 -d opcache.file_cache=\/tmp $(which cachetool) opcache:reset';<br \/>-               shell_exec( \"PATH={$path} {$cmd} 2&gt;&amp;1\" );<br \/>-               return;<br \/>+       if ( function_exists( 'shell_exec' ) ) {<br \/>+               $cachetool = trim( shell_exec( \"PATH={$path} which cachetool 2&gt;\/dev\/null\" ) );<br \/>+               if ( $cachetool ) {<br \/>+                       $cmd = 'php -d opcache.enable_cli=0 -d opcache.file_cache_only=0 -d opcache.file_cache=\/tmp $(which cachetool) opcache:reset';<br \/>+                       shell_exec( \"PATH={$path} {$cmd} 2&gt;&amp;1\" );<br \/>+                       return;<br \/>+               }<br \/>        }<br \/> <br \/>        \/\/ Fallback: direct FastCGI if cachetool.yml exists.<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-18985692","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18985692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18985692\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18985692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}