PHP downloads files while reading

PHP downloads files while reading … here is a solution to the problem.

PHP downloads files while reading

I have two PHP services.
One for other users to download the file.
The other gets an updated version of the file every once in a while.
Now I do it through flock().
I want to improve it by using link() – I mean downloading the file and then linking to the newly downloaded file. However, there is a problem with this approach because you cannot link() a file that has already been linked.

Any ideas?

Solution

Download the new file to a temporary file name, and then move it to the real file name. There is no need to deal with links or locks. Your file system usually knows what it does.

Just add some error checking and error handling.

Related Problems and Solutions