开发者

File can't run while being uploaded simultaneously via FTP

开发者 https://www.devze.com 2023-03-15 20:21 出处:网络
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 red

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 dow开发者_开发问答ntime 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???

0

精彩评论

暂无评论...
验证码 换一张
取 消