简体   繁体   English

PHP:将代码持续部署到服务器

[英]PHP: Continuous deployment of code to the server

I've been wondering about this forever. 我一直在想这个。 Say I have an API call I can access via www.example.com/api?call&param=value and this does something on my server which is written in PHP as my language of choice. 假设我有一个API调用,我可以通过www.example.com/api?call&param=value进行访问,这会在服务器上执行某些操作,并以PHP编写为我的选择语言。

Now, if I want to update the file that works directly with this API endpoint, I need to upload it to the server and effectively replace the old version of the document. 现在,如果我想更新可直接与此API端点一起使用的文件,则需要将其上传到服务器并有效地替换旧版本的文档。

However, if I were to call the API command via the address I provided WHILE I'm uploading the new file, I'd get an error saying that there was an unexpected end of file that should've been processing this command. 但是,如果我在上载新文件的同时通过提供的地址调用API命令,则会收到一条错误消息,提示应处理该命令的文件意外结束。 It is all logical - after all, the new document isn't fully uploaded yet so it has to be 'incomplete.' 完全合乎逻辑-毕竟,新文档尚未完全上载,因此必须“不完整”。

Obviously this issue can lead to many problems if I'd have 100 users trying to make this call while I'm uploading a new version and even more so if this call was working with some confidential or otherwise sensitive data. 显然,如果我有100个用户在上载新版本时尝试进行此调用,则可能导致许多问题,如果在某些机密或敏感数据下使用此调用,则可能会导致更多问题。 We could lose important data due to this, or have corrupted records in the database. 因此,我们可能会丢失重要数据,或者数据库中的记录已损坏。

So my simple question is, how do I circumvent this issue with deployment of new code? 所以我的简单问题是,如何通过部署新代码来规避此问题? How do companies with massive user traffic do it? 拥有大量用户流量的公司如何做到这一点? Can you provide me with any more links to read about this quirk? 您能否为我提供更多链接以阅读有关此怪癖的信息? Or at least tell me the jargon for this event? 或者至少告诉我这次活动的行话?

Thank you. 谢谢。

Or at least tell me the jargon for this event? 或者至少告诉我这次活动的行话?

It is hard to tell what issue you exactly experience, but it looks like you are talking about "an upgrade of a server without downtime". 很难说出您到底遇到了什么问题,但是您似乎正在谈论“在不停机的情况下升级服务器”。 This is how I would refer to it. 这就是我要提到的方式。 There are probably other terms used for this. 为此可能还有其他术语。

So my simple question is, how do I circumvent this issue with deployment of new code? 所以我的简单问题是,如何通过部署新代码来规避此问题?

Deployment of new code is a partial case of upgrade of any software in a host serving something. 部署新代码是主机中提供某些服务的任何软件升级的部分情况。 The deployment may include upgrade of the entire operation system, http server, database, etc. Commonly used strategy for "upgrade without downtime" are "rollover upgrade" (especially for sites with big traffic) and "switchover" (usually for small single host sites). 部署可能包括整个操作系统,http服务器,数据库等的升级。“无停机升级”的常用策略是“过渡升级”(特别是对于流量较大的站点)和“切换”(通常适用于小型单个主机)网站)。 Not sure if it is an overkill in case of only PHP code upgrade, maybe there are other strategies targeting only PHP environment. 不确定仅升级PHP代码是否过大,也许还有其他针对PHP环境的策略。

How do companies with massive user traffic do it? 拥有大量用户流量的公司如何做到这一点?

"Rollover upgrade" strategy commonly used in the distributed environments handling massive traffic. 通常在分布式环境中处理大量流量的“翻转升级”策略。 The idea is based on upgrade of multiple hosts one by one. 该想法基于一对一升级多个主机。 While one host is down during upgrade, traffic is redirected to other alive. 当一台主机在升级过程中关闭时,流量会重定向到其他活动状态。 When a host is up again, the other host is taken down. 当一台主机再次启动时,另一台主机将被关闭。 An so on, until all hosts are upgraded. 依此类推,直到所有主机都升级。

"Switchover" is a partial case of "rollover upgrade", when there is a single host only, ie not distributed. 当只有一个主机(即未分配)时,“切换”是“滚动升级”的部分情况。 The idea is simple, new code is deployed to new service point (usually new host, especially if system level things are being upgraded). 这个想法很简单,将新代码部署到新的服务点(通常是新主机,尤其是在系统级事物正在升级的情况下)。 The new service runs in parallel with old version service. 新服务与旧版本服务并行运行。 When new service is up and running, you switch traffic from old to new destination (updating DNS records, http server routing rules, or other depending on a level where you are switching). 当新服务启动并运行时,您将流量从旧目标切换到新目标(更新DNS记录,http服务器路由规则,或其他取决于切换级别)。 When all connections/ clients are redirected to new service eventually, old service is taken down. 当所有连接/客户端最终都重定向到新服务时,旧服务将被关闭。

Can you provide me with any more links to read about this quirk? 您能否为我提供更多链接以阅读有关此怪癖的信息?

Here is an example how switchover could be implemented for php app: https://webmasters.stackexchange.com/questions/22165/updating-a-web-app-without-any-downtime I am not sure if it implements "no downtime" strategy or just "minimal downtime" strategy. 这是一个如何为php应用实现切换的示例: https : //webmasters.stackexchange.com/questions/22165/updating-a-web-app-without-any-downtime我不确定它是否实现了“没有停机时间”策略或仅仅是“最小停机时间”策略。

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

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