What happens when an end user accesses a PHP file that is being overwritten at the same time?

I am creating a release process for deploying recently modified PHP files to a production server. I would like to know what happens when the end user accesses the PHP web page at the same time that it overwrites during release.

Are there any recommendations for releasing web scripts and code that take into account any problems that may arise in the scenario described above?

+4
source share
2 answers

I would like to know what happens when the end user accesses the PHP web page at the same time that it overwrites during release.

Depends on whether the file has already been completely overwritten. If not completely written, PHP will try to parse the incomplete file, which usually results in an error.

Are there any recommendations for releasing web scripts and code that take into account any problems that may arise in the scenario described above?

you can do many things, for example, to prevent access until you update the material (showing the maintenance page) or having several versions of the code base next to each other and the ability to switch one version live through a file- (symbolic links) or configuration server.

+4
source

There are two scenarios:

  • The user starts reading before starting to write the file.
  • The user starts reading after starting to write the file

In the first scenario, the user usually reads the old file (but this may vary depending on different file systems). Please note that you can modify several files that are related to each other, in which case the user may have incompatible versions of the files (for example, one file from version 1.1, which suddenly includes a file from version 1.2).

In another scenario, the user will read a partial file as described by hakre.

There are FTP servers that download the entire file under a temporary name, and then rename it when it is fully downloaded.

There are ways to completely avoid these problems, for example, by closing the site at boot time. If you have a balanced load level, you can delete one server after another and make updates offline without closing the website.

+1
source

All Articles