Clearing Cache without CLI on Shared Hosting Servers in Laravel 5
Although the Artisan command cache:clear effectively clears cached data, users seeking alternative methods without CLI access may encounter challenges, especially on shared hosting servers where control panel access is limited. This article delves into a workaround to address this concern.
To clear the cache, including the views cache, one can employ PHP's Artisan::call method. By integrating this method into a route, it becomes possible to invoke Artisan commands outside the traditional CLI environment.
Consider the following PHP code:
<code class="php">Route::get('/clear-cache', function() { $exitCode = Artisan::call('optimize:clear'); // return what you want });</code>
This code snippet defines a route that, when accessed via a GET request, calls the optimize:clear Artisan command. The optimize:clear command encompasses both cache:clear and view:clear, ensuring that both cache types are purged.
Alternatively, if desired, one can call Artisan::call('view:clear') specifically to clear only the views cache.
For further reference, the official Laravel documentation provides a comprehensive guide on calling Artisan commands outside the CLI environment.
It's worth noting that by default, Laravel stores application cache in the storage/framework/cache directory. However, this configuration can be customized by modifying the file driver in config/cache.php. By utilizing high-performance drivers like Redis or Memcached instead of a file-based cache, users can significantly enhance caching capabilities.
The above is the detailed content of How to Clear Cache in Laravel 5 Without CLI Access on Shared Hosting?. For more information, please follow other related articles on the PHP Chinese website!