开发者

Avoiding problem of overwriting files which are in use

For example on a high traffic web server.

To reduce problems when switching a file I usually rename the old file out and then rename in the new file.

I was told some time ago that 开发者_如何学运维renaming a file does not change the 'inode data' so that processes reading the file can keep doing so without glitches. And, of course, rather than copying in the new file it is faster and safer to rename a temp copy.

Is this still best practice and if not what do you do?


Assuming that you use Apache http-server.

Apache normally uses the kernel function sendfile to send static files, that means that it is up to the kernel to cache the file contents and keep track of when it changes.

You should create the new file and then replace the old file with the new file, e.g.

mv newfile oldfile

Then the contents of the new file will be served instead of the old file. Note that any cache settings enabled on the HTTP level may affect whether browsers and proxies deliver the old file or the new file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜