Home  >  Article  >  Backend Development  >  How to Clear Cache in Laravel 5 Without CLI Access on Shared Hosting?

How to Clear Cache in Laravel 5 Without CLI Access on Shared Hosting?

DDD
DDDOriginal
2024-11-02 09:10:29594browse

How to Clear Cache in Laravel 5 Without CLI Access on Shared Hosting?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn