views:

43

answers:

1

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?

+1  A: 

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.

Ernelli
Did you not mean to type "mv newfile oldfile"?
zaf
Thank you for notifying the error.
Ernelli