欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

5清除缓存laravel共享托管服务器 Laravel 5 - Clear cache in shared hosting server

问题是很清楚的

php artisan cache:clear

有什么工作来清除缓存像上面我们使用CLI。我用一个著名的共享托管服务,但是按照我的计划我没有控制面板的访问。

基本上我想清除视图缓存。

我看到一个问题几乎一样,但它不会帮助我。

先谢谢了

分享改善这个问题
 
 
运行laravel共同主办,是疯狂的,在我看来,正是这种原因。你是如何运行的迁徙?ceejayoz7月16 15 15:01
  
“ceejayoz ..其实我刚开始这个项目,和我第一次laravel项目以及。我不是来这迁移的事情..杜克在7月19 15:58
 
“跑步laravel共同主办,是疯狂的“@ ceejayoz…但这是真实的世界。有时候你不得不因为没有选择。elb98rm16年9月1日在8:47
 
“elb98rm从数字海洋开始在5美元/月的VPS。总有一个选择,包括没有工作的客户谁愿意支付5美元/月的托管。ceejayoz16年9月1日在13:44
 
“ceejayoz不相关的-我经常工作的地方,这不是钱的问题,这是关系或主机和内部政治。而且,有时却达不到你的整个部门。真实的世界意味着你有时需要工作。你很幸运或庇护如果你从来没有与另一个人的选择工作…elb98rm16年9月2日14:50

6个答案 正确答案

了投票四十七投票表决认可的

你可以打电话给外面的CLI命令一个工匠。

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

你可以在这里查看官方文档HTTP:/ / laravel。COM /文档/ 5 /工匠#命令调用外部命令


更新

有没有办法删除视图缓存。既不php artisan cache:clear确实

如果你真的想清楚的视图缓存,我觉得你要自己写的artisan命令和调用它就像我之前说的,或完全跳过工匠路径和清晰的视图缓存在某些类,从控制器或路由呼叫你。

但是,我真正的问题是你真的需要清晰的视图缓存?在一个项目,我目前的工作,我几乎100缓存的看法和他们的重量小于1 MB,而我vendor目录> 40 MB。我不想查看缓存在磁盘使用一个真正的瓶颈,没有明确的实际需要。

至于应用程序缓存,它是存储在storage/framework/cache目录,但只有当你配置文件司机config/cache.php。你可以选择很多不同的驱动程序,如redismemcached,提高了基于文件的缓存性能。

分享提高这个答案
 
  
但它不似乎是工作!杜克在7月16 15 14 13
  
什么隐藏物你想清楚了吗?这个cache:clear命令与应用程序缓存,一个是访问的Cache外观.马可Pallante则7月16 15 15:19
  
我想清晰的视图缓存,有很多保存在文件夹视图缓存页。还有一个问题,当说应用程序缓存,这是所有目录,它的目标。杜克4月19日15点47分
  
谢谢你的解释!我不担心磁盘空间:)但有个问题,如果视图缓存不清除,那么如何在视图的新变化得到网站的影响,是任何I/O检查发生在laravel?杜克在6月19日15时48
  
我认为这是一个时间戳检查文件,这比重建叶片模板更快马可Pallante则在8月19日15点02分

我可以看到:http://itsolutionstuff.com/post/laravel-5-clear-cache-from-route-view-config-and-all-cache-data-from-applicationexample.html

可以使用下面的代码与新的清除缓存的命令:

//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>';
});

给清除缓存每个人都可能是不必要的,尤其是在生产环境中,所以我建议评论路线,当需要的时候,去评论的代码和运行路线。

分享提高这个答案
 

基本上我想清除视图缓存。

现在有5.1个命令,laravel

php artisan view:clear
分享提高这个答案
 

我希望这有助于人

laravelFolder/bootstrap/cache然后重命名config.php要你想要的任何东西,如config.php_old并重新加载你的网站。那应该像巫术。

快乐编码…

分享提高这个答案
 
  
我确认。在laravel,作品5.4。我的弓。西蒙5月31日下午14
  
唯一的解决方案!如果你想知道为什么吗?只有上帝知道路易斯孔特雷拉斯在21:03月27
  
证实它擦痛在**在主持laravel 5.4从Windows到共享主机的…谢谢您!!!rikudo疼痛在3月17:52

配置缓存配置的laravel遍布几十个文件,和including他们每个人的每个请求是一个昂贵的过程。把你所有的配置文件为一体,使用:1

php artisan config:cache

记住配置的任何更改将不会有任何影响你一旦缓存它。刷新配置缓存,再次运行上面的命令。如果你想彻底摆脱配置缓存,润1

php artisan config:clear

路由缓存路由也是一个昂贵的任务在laravel。缓存routes.php文件运行以下命令:1

php artisan route:cache

记住,它不工作与关闭。如果你使用闭包这是移动到控制器的好机会,为工匠命令将抛出一个异常,当试图编译的路线,必然会倒闭而不是一个适当的控制器的方法。在同等配置的缓存,以routes.php任何变化将不会有任何影响。刷新缓存,运行上面的命令,每次你改变路线文件。完全摆脱了路由缓存,运行下面的命令:1

php artisan route:clear

ClassMap优化

它是分布在数百个大中型项目的PHP文件并不罕见。良好的编码行为支配我们,凡事都有它自己的文件。这,当然,并不是没有缺点。Laravel:对于每个请求不同的数十个文件,这是要做一个昂贵的事。

因此,一个好的优化方法是声明这些文件用于为每个请求(这是,例如,你所有的服务提供商、中间件和一些),只有一个文件结合起来,将每个请求之后加载。这不同于将所有JavaScript文件合并成一个,所以浏览器会减少对服务器的请求。

额外的编译文件(一次:服务提供商、中间件等)应宣布你在配置文件中的关键compile.php。一旦你把这一切必不可少的了你的应用程序的每个请求,将它们串联在一个文件中:1

php artisan optimize --force

作曲家自动优化

这是一个不仅用于laravel,但任何应用程序,利用作曲家。

我会先解释如何psr-4加载工作,然后我会告诉你什么是命令你应该运行优化。如果你不知道作曲家的作品感兴趣,我建议你直接跳到控制台命令。

当你问compsoser为应用程序\控制器\ authcontroller类,它首先搜索在ClassMap直接关联。这是一个与ClassMap类和文件的1对1的关联数组。因为,当然,你没有手动添加登录类及其相关的文件到ClassMap,作曲家将搜索命名空间中,因为应用程序是一个psr-4命名空间,这是默认情况下,Laravel和它的应用程序/文件夹关联,作曲家将尝试转换psr-4类名称基本的字符串操作程序文件名。最后,它猜测程序\控制器\ authcontroller必须位于一个authcontroller.php文件,这是一个控制器/文件夹应该幸运的是命名空间中的文件夹,这是应用程序/。

这一切的努力只获得应用程序\控制器\ authcontroller类存在于应用程序/控制器/ authcontroller.php文件。为了扫描您的整个应用程序和作曲家创造的类和文件的直接一对一关联,运行以下命令:1

composer dumpautoload -o

记住,如果你已经跑php工匠优化力,你不用跑这一个了。由于优化命令已经告诉作曲家创造一个优化的加载。

分享提高这个答案
 

你可以通过FTP和清除存储\框架视图用于laravel 5存储\意见laravel 4或应用程序文件夹连接。

分享提高这个答案
 

来自 https://stackoverflow.com/questions/31455829/laravel-5-clear-cache-in-shared-hosting-server

The question is pretty clear.

php artisan cache:clear

Is there any work around to clear the cache like above we using in CLI. I am using a famous shared hosting service but as per my plan I don't have control panel access.

Basically I want to clear the views cache.

I saw aquestionalmost same like this, but it doesn't helps me.

Thanks in advance.

shareimprove this question
 
1 
Running Laravel on shared hosting is insane, IMO, for precisely this sort of reason. How are you running migrations?ceejayozJul 16 '15 at 15:01
  
@ceejayoz .. Actually I just started this project, and its my first laravel project as well. I didn't come to this migration thing yet..dukeJul 19 '15 at 7:58
4 
"Running Laravel on shared hosting is insane" @ceejayoz ... But this is the real world. Sometimes you have to because there's no choice.elb98rmSep 1 '16 at 8:47
1 
@elb98rm A VPS from Digital Ocean starts at $5/month. There's always a choice, including not working for a client who's unwilling to pay $5/month for hosting.ceejayozSep 1 '16 at 13:44
4 
@ceejayoz Not relevant - often I've worked for places where it's not the money, it's the relationship or the host and internal politics. Moreover - sometimes it's literally not up to your entire department. The real world means you sometimes need to work with a situation. You're lucky or sheltered if you've never had to work with another person's choices...elb98rmSep 2 '16 at 14:50

6 Answers 正确答案

 

You can call an Artisan command outside the CLI.

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

You can check the official doc herehttp://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli


Update

There is no way to delete the view cache. Neitherphp artisan cache:cleardoes that.

If you really want to clear the view cache, I think you have to write your ownartisancommand and call it as I said before, or entirely skip theartisanpath and clear the view cache in some class that you call from a controller or a route.

But, my real question isdo you really need to clear the view cache? In a project I'm working on now, I have almost 100 cached views and they weight less then 1 Mb, while myvendordirectory is > 40 Mb. I don't think view cache is a real bottleneck in disk usage and never had a real need to clear it.

As for theapplication cache, it is stored in thestorage/framework/cachedirectory, but only if you configured thefiledriver inconfig/cache.php. You can choose many different drivers, such asRedisorMemcached, to improve performances over a file-based cache.

shareimprove this answer
 
  
But it doesn't seems to be working!dukeJul 16 '15 at 14:13
  
Whatcacheare you trying to clear? Thecache:clearcommand works with theapplication cache, the one that is accessed from theCachefacade.Marco PallanteJul 16 '15 at 15:19
  
I want to clear the view cache, there are a lot of pages saved in view cache folder. One more question, when says application cache, which are all the directories it targets.dukeJul 19 '15 at 4:47
  
Thanks for the explanation!. I am not worried bout disks space :) But one question if view cache is not clearing, then how the new changes in view get affect in the website, is that any I/O check happening in laravel ?dukeJul 19 '15 at 6:48
  
I think it does a timestamp checking on files, which is faster than rebuilding the blade templateMarco PallanteJul 19 '15 at 8:02

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

is it possible to use the code below 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>';
});

It's not necessary to give the possibility to clear the caches to everyone, especially in a production enviroment, so I suggest to comment that routes and, when it's needed, to de-comment the code and run the routes.

shareimprove this answer
 

Basically I want to clear the views cache.

There is now a command in Laravel 5.1 for that

php artisan view:clear
shareimprove this answer
 

I hope this helps someone

Go tolaravelFolder/bootstrap/cachethen renameconfig.phpto anything you want eg.config.php_oldand reload your site. That should work like voodoo.

Happy Coding...

shareimprove this answer
 
  
I confirm. Works in laravel 5.4. Me bows.simonMay 31 at 1:14
  
The one and only solution! If you wonder why works ? only god knowsLuis ContrerasJun 27 at 21:03
  
Confirmed it wipe the pain in the a** while hosting laravel 5.4 from windows to shared hosting.... THANK YOU!!!Rikudo PainJul 3 at 17:52

Config cachingThe laravel config spreads across dozens of files, andincludingevery one of them for each request is a costly process. To combine all of your config files into one, use:1

php artisan config:cache

Keep in mind that any changes to the config will not have any effect once you cache it it. To refresh the config cache, run the above command again. In case you want to completely get rid of the config cache, run1

php artisan config:clear

Routes cachingRouting is also an expensive task in laravel. To cache the routes.php file run the below command:1

php artisan route:cache

Mind that it doesn't work with closures. In case you're using closures this is a great chance to move them into a controller, as the artisan command will throw an exception when trying to compile routes that are bound to closures instead of a proper controller methods.In the same as the config cache, any changes to routes.php will not have any effect anymore. To refresh the cache, run the above command everytime you do a change to the routes file. To completely get rid of the route cache, run the below command:1

php artisan route:clear

Classmap optimization

It's not uncommon for a medium-sized project to be spread across hundreds of PHP files. As good coding behaviours dictate us, everything has its own file. This, of course, does not come without drawbacks. Laravel has to include dozens of different files for each request, which is a costly thing to do.

Hence, a good optimization method is declaring which files are used for every request (this is, for example, all your service providers, middlewares and a few more) and combining them in only one file, which will be afterwards loaded for each request. This not different from combining all your javascript files into one, so the browser will have to make fewer requests to the server.

The additional compiles files (again: service providers, middlewares and so on) should be declared by you in config/compile.php, in the files key. Once you put there everything essential for every request made to your app, concatenate them in one file with:1

php artisan optimize --force

Optimizing the composer autoload

This one is not only for laravel, but for any application that's making use of composer.

I'll explain first how the PSR-4 autoload works, and then I'll show you what command you should run to optimize it. If you're not interested in knowing how composer works, I recommend you jumping directly to the console command.

When you ask compsoser for the App\Controllers\AuthController class, it first searches for a direct association in the classmap. The classmap is an array with 1-to-1 associations of classes and files. Since, of course, you did not manually add the Login class and its associated file to the classmap, composer will move on and search in the namespaces.Because App is a PSR-4 namespace, which comes by default with Laravel and it's associated to the app/ folder, composer will try converting the PSR-4 class name to a filename with basic string manipulation procedures. In the end, it guesses that App\Controllers\AuthController must be located in a AuthController.php file, which is in a Controllers/ folder that should luckily be in the namespace folder, which is app/.

All this hard work only to get that the App\Controllers\AuthController class exists in the app/Controllers/AuthController.php file. In order to have composer scanning your entire application and create direct 1-to-1 associations of classes and files, run the following command:1

composer dumpautoload -o

Keep in mind that if you already ran php artisan optimize --force, you don't have to run this one anymore. Since the optimize command already tells composer to create an optimized autoload.

shareimprove this answer
 

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

shareimprove this answer
 

来自 https://stackoverflow.com/questions/31455829/laravel-5-clear-cache-in-shared-hosting-server


普通分类: