title: Best way to replace file on server
body: <p>I have to write script in PHP which will be dynamicly replace some files on server from time to time. Easy thing, but the problem is that I want to avoid situation when user request this file during replacing. Then he could get uncompleted file or even error.</p>
  
  <p>Best solution to me is block access to my site during replacing by e.g. setting .htaccess redirecting all requests to page with information about short break. But normally .htaccess file already exist, so there may be situation when server gets uncomplited .htaccess file.</p>
  
  <p>Is there any way to solve it?</p>
  
  <p><strong>Edit:</strong> Thank you so much for all answers, guys. You are briliant.</p>
  
  <p>@ircmaxell Your idea sounds great for me. I read what dudes from PHP.net wrote and I don't know if I understand all correctly.</p>
  
  <p>So, tell me: If I do all steps you wrote and add apc.file_update_protection to my php.ini, there will be no way to get uncompleted file by user by any time? There will be always one, correct file? Are you sure at 100% ?</p>
  
  <p>It is very important to me coz these replacements will be very often and there is big chance to request file during renaming.</p>