R
R
roid912015-12-22 15:27:10
PHP
roid91, 2015-12-22 15:27:10

What is the best way to change php files on a working project?

There is a site on which, for example, 100 people are sitting at the same time.
The task is to change some php scripts so that at the moment of pumping out this file to the server, the user who opened the site just at the same moment would not get a Fatal error.
Please tell me what options for performing this task are and in which direction it is best to dig ...
Thank you.
UPD. The main problem is that the file is downloaded, for example, via FTP Notepad ++, and often (I look at the logs) people get a Fatal error, because. files, CMS cores are changed...
At the same time, if you change the file, conditionally, through Upload php (CMS file manager), this problem does not arise...
So I'm thinking, maybe there are some gadgets for the (S)FTP server, which, say, buffer the file until it is completely uploaded to the server, and then already replace the final file with it?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
Y
Yuri, 2015-12-22
@roid91

When you upload via CMS, the file is essentially uploaded to a temporary file, and then a move occurs, which, if the temporary file and the target are on the same partition of the file system, is atomic (that is, either at one point in time it is an old file, either new), or if there is a move between sections - it still happens very quickly.
In the case when you upload via ftp, the old file is first deleted, i.e. it becomes inaccessible, and then a new one begins to pour. At this point, "crap" occurs.
There are several ways out:
- about the first one (I would not say that it is very simple, but still quite effective), you already wrote D' Normalization in the second paragraph.
- the second is to upload files not via ftp, but, say, using rsync from a certain directory where you are already uploading via ftp. That is, they uploaded it, checked that there was no need to upload anything else - they launched rsync on the server from this directory to production. rsync also copies differing files first to a temporary file and then "movie" to a permanent location.
- the third - can be with jambs, use, for example, opcache in PHP and set in the opcache parameters not to touch the file until it gets old, for example, for a few seconds. Seconds are determined empirically, depending on the speed of your fill.
- the fourth ... and who knows, you can come up with a lot of things. For example, store files in an SVN or GIT repository, and launch a post-hook on commit / push, which, for example, will synchronize files with the same rsync or use some kind of Jenkins ... a lot of options, the main thing is not to touch the production files yourself.

D
D', 2015-12-22
@Denormalization

Oh, they advised ..
There are 2 simple upgrade options:
1) We hang the "Everything is gone. We are under repair.", and while the users are in shock, we are doing the upgrade.
2) Learning to use symlinks. In the next folder, we expand the updated project, and with a deft movement of the hand we switch the symlink to another folder.
If there are many "terrible" ways, but these two are the most simple and effective.

M
MetaDone, 2015-12-22
@MetaDone

the user will not even notice this, unless of course you have a file of several gigs in size. If so - upload when there is no one, and do not display errors on the site, but write them to the logs. The user should not suspect at all that the site can produce errors.
If absolutely necessary - hang a sign "site under maintenance", fill in everything you need and remove the sign and do not make problems from scratch

G
galsik, 2015-12-22
@galsik

This can be done through output buffer management, php has such built-in functions but if you ask such questions it will be difficult for you.

A
Andrey Smirnov, 2015-12-22
@And__Smi

I don't think it's somehow possible. Of course, I have assumptions:
1. It is necessary to disable access to this file, that is, so that a regular user cannot access it, only those who write scripts (as an option: remove links to it everywhere, or you can even load another document type 404 errors - this page does not exist or 503 errors - the page is under development).
2. This method is already more relevant - create a test domain on the hosting and conduct your "experiments" on this test domain. As a result, you do not touch the main site, the user does not see your fatalities, but the site also successfully updates the files that you upload if your experiments are successful.
BUT: if you ask that it be on this site and that it should be on this page, then I can’t tell you. Since in any case, if you make a mistake somewhere and a fatal pops up, you will know what the mistake is. And to disable it so that the user does not see and at the same time that he sees a normal page - it seems to me impossible. Mistakes for that and mistakes so that you can see where you made a mistake.

A
Anton B, 2015-12-22
@bigton

The probability that one in 100 people will get a "white screen" when you re-upload scripts is very low, so don't worry. And you can add an error page like "Oops! Something went wrong, reload the page."

A
Alexander, 2015-12-22
@aspetek

Upload the archive, unpack on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question