简体   繁体   中英

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.

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.

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. 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. 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). Not sure if it is an overkill in case of only PHP code upgrade, maybe there are other strategies targeting only PHP environment.

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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