Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP download file while reading

I have two PHP services. One that let other users to download a file. Another that fetch every some time an updated version of that file. Now I am implementing it through flock(). I thought of improving it by using link() - I mean downloading the file and then link to the new downloaded file. But, there is a problem with this way because you cannot link() a file that is already is being link.

Any ideas?

like image 876
Ben Laniado Avatar asked Jun 14 '26 01:06

Ben Laniado


1 Answers

Download the new file to a temporary filename and then move it over to the real filename. No need to deal with links or locks. Your filesystem normally knows what it does.

Just add some error checking and deal with errors.

like image 159
hakre Avatar answered Jun 16 '26 15:06

hakre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!