I need to write a script in PHP that from time to time will dynamically replace some files on the server. The simple thing, but the problem is that I want to avoid a situation where the user requests this file during the replacement. Then it could receive an incomplete file or even an error.
The best solution for me is to block access to my site during the replacement, for example. setting .htaccess redirect all requests to a page with information about a short break. But usually a .htaccess file already exists, so a situation may arise when the server receives a disconnected .htaccess file.
Is there any way to solve it?
Edit: Thanks so much for all the answers guys. You are friendly.
@ircmaxell Your idea is great for me. I read what they write from PHP.net, and I don’t know if I understand correctly.
So tell me: if I do all the steps you wrote and add apc.file_update_protection to my php.ini, there will be no way to get the incomplete file by the user at any time? Will there always be one correct file? Are you 100% sure?
It is very important for me that these replacements are performed very often, and there is a big chance to request a file during renaming.
source
share