php - File can't run while being uploaded simultaneously via FTP


Not sure if this is server related or normal behavior, but I thought I'd ask. I run a relatively high-traffic website (200k+ uniques/week) and we serve lots of links through a PHP file containing redirects.

The only problem is, I need to update this file frequently, which I do via SFTP. The file is around 800k in size and takes a second or so to download. However, users have informed me that sometimes the links redirected through the PHP file don't work, and I've realized that this only happens when I'm uploading or downloading the file via SFTP.

So my question is: Is there any way I can keep the file executable for users while I upload new copies of it via FTP? This downtime is bothersome for my users. Is this some setting in Linux that I'm not aware of, or is there nothing I can do about this? If it makes a difference, my server is running Centos.




Upload it as a different filename, and then rename it to clobber the old one. The upload takes significant time (if anything beyond 'instantaneous' is significant). rename (or mv) is atomic and won't make your users wait. You could take as much time as you need uploading the file, and then in a split second rename it.




The problem is that the file transfer is not atomic. It rewrites the file as its being uploaded. Which causes the file to be incomplete if the file is downloaded in the meantime.

If you upload the file into another location and then move the file into its correct location after the upload is complete you will replace the file atomically.




Pmivdb actually has it. Upload it at a temp file, then rename it (make sure to keep a copy of the old one). That is really your best (only?) option.




if you put the files in a separate folder and increment the file names is there some php script which would use the latest file???

People are also looking for solutions to the problem: How to return php code from mysql record?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.