Laravel 5 - Clear cache on shared hosting server

The question is pretty clear.

php artisan cache:clear 

Is there a workaround to clear the cache, as we used above in the CLI. I use the popular shared hosting service, but according to my plan, I do not have access to the control panel.

** I want to clear the view cache. **

I saw a question almost the same as this one, but it does not help me.

Thank you in advance.

+111
command-line-interface php laravel-5
Jul 16 '15 at 13:38
source share
16 answers

You can invoke the Artisan command outside the CLI.

 Route::get('/clear-cache', function() { $exitCode = Artisan::call('cache:clear'); // return what you want }); 

You can check the white paper here http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli




Update

Unable to delete view cache. Neither php artisan cache:clear .

If you really want to clear the presentation cache, I think you need to write your own artisan command and call it, as I said, or completely skip the artisan path and clear the presentation cache in some class, you are calling from the controller or route.

But, my real question is: do you really need to clear the browsing cache ? In the project I'm working on now, I have almost 100 cached views, and they weigh less than 1 MB, and my vendor directory is β†’ 40 MB. I do not think that the viewing cache is a real bottleneck in the use of the disk and never needed to clear it.

As for the application cache, it is stored in the storage/framework/cache directory, but only if you configured the file driver in config/cache.php . You can select many different drivers, such as Redis or Memcached, to improve performance over the file cache.

+128
Jul 16 '15 at 13:43 on
source share

I hope this helps someone

Go to laravelFolder/bootstrap/cache , then rename config.php to whatever you want, for example. config.php_old and reload your site. This should work like voodoo.

Happy coding ...

+44
Feb 27 '17 at
source share

As I see it: http://itsolutionstuff.com/post/laravel-5-clear-cache-from-route-view-config-and-all-cache-data-from-applicationexample.html

You can use the following code with the new clear cache commands:

 //Clear Cache facade value: Route::get('/clear-cache', function() { $exitCode = Artisan::call('cache:clear'); return '<h1>Cache facade value cleared</h1>'; }); //Reoptimized class loader: Route::get('/optimize', function() { $exitCode = Artisan::call('optimize'); return '<h1>Reoptimized class loader</h1>'; }); //Route cache: Route::get('/route-cache', function() { $exitCode = Artisan::call('route:cache'); return '<h1>Routes cached</h1>'; }); //Clear Route cache: Route::get('/route-clear', function() { $exitCode = Artisan::call('route:clear'); return '<h1>Route cache cleared</h1>'; }); //Clear View cache: Route::get('/view-clear', function() { $exitCode = Artisan::call('view:clear'); return '<h1>View cache cleared</h1>'; }); //Clear Config cache: Route::get('/config-cache', function() { $exitCode = Artisan::call('config:cache'); return '<h1>Clear Config cleared</h1>'; }); 

No need to give everyone the opportunity to clear the caches, especially in the production environment, so I suggest commenting on these routes and, when necessary, cancel the comment and start the routes.

+42
Jan 14 '17 at 13:19
source share

Configuration caching laravel configuration extends to dozens of files, and including each of them in each request is an expensive process. To merge all your configuration files into one, use:

 php artisan config:cache 

Keep in mind that any configuration changes will have no effect after you cache them. To update the configuration cache, run the specified command again. If you want to completely get rid of the configuration cache, run

 php artisan config:clear 

Routing Caching Routing is also an expensive task in Laravel. To cache the rout.php file, run the following command:

 php artisan route:cache 

Keep in mind that this does not work with closures. If you use closures, this is a great chance to move them to the controller, since the artisan team throws an exception when trying to compile routes that are tied to closures, instead of the correct controller methods. In the same order as the configuration cache, any changes to route.php will no longer have any effect. To update the cache, run the above command every time you make changes to the routes file. To completely get rid of the route cache, run the following command:

 php artisan route:clear 

Class Map Optimization

Often a medium-sized project extends to hundreds of PHP files. As good coding behavior tells us, everything has its own file. This, of course, is not without its drawbacks. Laravel must include dozens of different files for each request, which is a costly affair.

Therefore, a good optimization method is to declare which files are used for each request (for example, all your service providers, middleware, and some others), and combine them into one file, which will subsequently be downloaded for each request. This is no different than combining all your javascript files into one, so the browser will have to make fewer requests to the server.

Additional compilation files (again: service providers, middleware, etc.) Must be declared by you in config / compile.php, in the key files. After you put everything you need there for every request to your application, merge them into a single file with:

 php artisan optimize --force 

Composer startup optimization

This is not only for laravel, but also for any application using the composer.

First, I will explain how PSR-4 autoload works, and then I will show which command you need to execute in order to optimize it. If you are not interested in knowing how the composer works, I recommend switching directly to the console command.

When you ask App\Controllers\AuthController class App\Controllers\AuthController , it first looks for a direct link in the class map. The class map is an array with unambiguous associations of classes and files. Since, of course, you did not add the Login class and the associated file manually to the class map, composer will continue to search the namespaces. Because App is the PSR-4 namespace that comes with Laravel by default and is associated with the app/ folder, composer will try to convert the PSR-4 class name to a file name using basic string manipulation procedures. In the end, he assumes that App\Controllers\AuthController should be in the AuthController.php file, which is in the Controllers/ folder, which, fortunately, should be in the namespace folder, which is app/ .

All this hard work is just to get the class App\Controllers\AuthController in the file app/Controllers/AuthController.php . For the composer to scan the entire application and create direct links of classes and 1-to-1 files, run the following command:

 composer dumpautoload -o 

Keep in mind that if you have already run php artisan optimize --force, you no longer need to run it. Because the optimize command already tells the composer to create optimized startup.

+38
Jun 27 '17 at 9:01
source share

This package is for php ^ 7.0 and ^ laravel5.5 .

Use this package in a cronjob that I created just for this purpose. I also faced the same situation. https://packagist.org/packages/afrazahmad/clear-cached-data Install it and run:

 php artisan clear:data 

and it will run the following commands automatically

 php artisan cache:clear php artisan view:clear php artisan route:clear php artisan clear-compiled php artisan config:cache 

Hope it helps.

If you want to start it automatically at a specific time, you will first need to install crnjob. eg

  in app/console/kernel.php 

In the schedule functions:

 $schedule->command('clear:data')->dailyAt('07:00'); 
+25
Mar 01 '18 at 7:04
source share

Basically I want to clear the view cache.

Laravel 5.1 now has a command for

 php artisan view:clear 
+17
Nov 22 '16 at 22:58
source share

You can connect via FTP and clear the storage\framework\views folder for laravel 5 or the app\storage\views for laravel 4 .

+8
Jul 27 '15 at 17:19
source share

To clear the entire cache outside the CLI , do this; This works for me.

 Route::get('/clear', function() { Artisan::call('cache:clear'); Artisan::call('config:clear'); Artisan::call('config:cache'); Artisan::call('view:clear'); return "Cleared!"; }); 
+6
Nov 08 '18 at 4:33
source share
 php artisan view:clear 

clear cached views

+3
Oct 05 '18 at 12:02
source share

You can do this if you use Lumen from Laravel in the routes/web.php :

 use Illuminate\Support\Facades\Artisan; $app->get('/clear-cache', function () { $code = Artisan::call('cache:clear'); return 'cache cleared'; }); 
+1
Dec 17 '17 at 17:50
source share

You can also do this through a router, similar to Francesco's answer, but with less mess in the router configuration

 Route::get('/artisan/{cmd}', function($cmd) { $cmd = trim(str_replace("-",":", $cmd)); $validCommands = ['cache:clear', 'optimize', 'route:cache', 'route:clear', 'view:clear', 'config:cache']; if (in_array($cmd, $validCommands)) { Artisan::call($cmd); return "<h1>Ran Artisan command: {$cmd}</h1>"; } else { return "<h1>Not valid Artisan command</h1>"; } }); 

Then run them by visiting http: //myapp.test/artisan/cache-clear etc. If you need to add / edit valid Artisan commands, just update the $ validCommands array.

+1
Jun 22 '18 at 9:17
source share

It worked for me. In your project, go to: storage> framework> views. Delete all files and refresh the page.

+1
Aug 11 '18 at 10:27
source share

I used this page several times to copy and paste quick commands into the composer, so I wrote a command that executes these commands in a single artisan team.

 namespace App\Console\Commands\Admin; use Illuminate\Console\Command; class ClearEverything extends Command { protected $signature = 'traqza:clear-everything'; protected $description = 'Clears routes, config, cache, views, compiled, and caches config.'; public function __construct() { parent::__construct(); } public function handle() { $validCommands = array('route:clear', 'config:clear', 'cache:clear', 'view:clear', 'clear-compiled', 'config:cache'); foreach ($validCommands as $cmd) { $this->call('' . $cmd . ''); } } } 

Put in the app\Console\Commands\Admin folder

then run the command in php artisan traqza:clear-everything

Good coding.

Github β†’ https://github.com/Traqza/clear-everything

+1
Feb 10 '19 at 6:39
source share

Although I strongly disagree with the idea of ​​running the laravel application on shared hosting (a bad idea), this package is likely to solve your problem. This is a package that allows you to execute some artisan teams from the Internet. This is far from perfect, but may work for some cases.

https://github.com/recca0120/laravel-terminal

0
Jan 15 '18 at 17:21
source share

Cache :: flush (); https://laravel.com/docs/5.7/cache#events This work in the Handler class extends ExceptionHandler

0
Dec 22 '18 at 9:03
source share

Try it also

for Kli

php artisan clear: cache

for using craft team

  Route::get('/clear-cache', function() { $exitCode = Artisan::call('cache:clear'); return 'Application cache cleared'; 

});

[ https://www.tutsmake.com/laravel-clear-cache-using-artisan-command-cli/†►1]

  [1]: https://www.tutsmake.com/laravel-clear-cache-using-artisan-command-cli/ 
0
Jan 29 '19 at 5:43
source share



All Articles