Synchronising images in the filesystem with the live server
I have a local PHP web application that is being updated daily with new content and updated content. This is store in MYSQL5.
I am also maintaining a filesystem of related images, that are tracked by a table in the mysql. I have NOT gone down the blob route - this is using a linux filesystem.
Having performed a dail开发者_开发技巧y update on the data what is the best method to synchronise the images with the server?
I am using PHP5, but not adverse to external scheduling program it works.
My images are stored in such order:
media/id/imagename.jpg
ie.
media/123/123_1.jpg
media/123/123_2.jpg
media/1234/1234_1.jpg
media/1234/1234_2.jpg
Nomrally the answer to the question of how to keep files in sync would be to use a tool designed for the job - like rsync, or use a replicated / shared filesystem. However in your case, presumably you want to the mysql records to reflect the state of the files.
In order to do this I would recommend writing a pair of PHP scripts (one at the sending end, one at the receiving end). To add some security in here, I'd not let the receiving end capture any old data - but rather have the origin server make a request to the receiving end providing the metadata - the receiving end would then poll the image data from the origin to create the copy (and write the mysql record when this has completed).
It might be a good idea to think about implementing some sort of transactional control too - to sensure that both ends are in sync without having to copy every file.
精彩评论