简体   繁体   English

Laravel全球拒绝访问网站进行更新

[英]Globally deny access to website for update, Laravel

This is a fairly open question as i am not sure what the best practice could/should be for this type of activity. 这是一个相当开放的问题,因为我不确定此类活动的最佳做法是/应该是什么。

The scenario; 场景; A user based website (with logged in user areas and user editable content) needs to have several operations performed that will manipulate live data. 一个基于用户的网站(具有登录的用户区域和用户可编辑的内容)需要执行一些操作,以操作实时数据。 To stop any errors occurring due to users simultaneously editing as the update is taking place, i need to shut out the users temporarily. 要阻止由于用户在进行更新时同时进行编辑而导致的任何错误,我需要暂时将用户拒之门外。

I don't currently have a config database table, just a config file. 我目前没有配置数据库表,只有一个配置文件。 Two things need to happen; 需要发生两件事;

  • An update to the config happens to stop the users accessing certain areas of the website during the update - this is then reverted once the update is complete. 对配置的更新恰巧会阻止用户在更新过程中访问网站的某些区域-更新完成后将还原为该状态。
  • The website (or at least portions on the site) need to be checked before every request for said portions of the site - so whatever the method, it needs to be lightweight 在对网站的所述部分的每次请求之前,都需要检查网站(或网站的至少一部分)-因此,无论采用哪种方法,都必须轻巧

This is site built on Laravel. 这是建立在Laravel上的网站。

Thanks! 谢谢!

There is a simple artisan command for that. 为此有一个简单的工匠命令。 Use this to shut down the application: 使用它来关闭应用程序:

php artisan down

And this to turn it back on: 并将其重新打开:

php artisan up

I'll use serveral measures in this case. 在这种情况下,我将使用服务器措施。

  1. put the code in try - catch block so that if something goes wrong, you can grcefully show an error message. 将代码放入try-catch块中,以便在出现问题时可以显示错误消息。

  2. If there are mulitple executions invovled, then better use DB::transaction() and the system will roll back automatically if it encounters an error. 如果涉及多个执行,则最好使用DB::transaction() ,如果遇到错误,系统将自动回滚。

  3. If you really want to put certain features on maintence mode, then put those routes in Route::group() and use a middleware for that group only. 如果您真的想将某些功能放在维护模式下,则将这些路由放在Route::group()并仅将中间件用于该组。 In that middleware, return response with 503 status. 在该中间件中,返回状态为503的响应。 This way, you can put certain routes into maintanace mode while the rest will give 200 ok response. 这样,您可以将某些路由置于维护模式,而其余路由将给出200 OK响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM