In PHP, I would not recommend it for a number of reasons.
I have exactly what you need as a python application.
This application is built to run as a service, you just start it and forget about it :)
Application: https://gist.github.com/8f62786582c6933395eb
Shell: https://gist.github.com/e08a99937c6f5deac4ab
Note: the shell file should be called fsyncd not fsyncd.sh :)
PHP version above:
https://gist.github.com/3963cbc58793ff7e9773
Note. You need to make it work on both sites and configure each to connect to the other, and configure them to run using clones. Preferably not WP carmines.
I have a directory path that will sync here:
define("PATH_DATA", PATH_ROOT . "data" . DIRECTORY_SEPARATOR);
In my case, the data folder is in the script folder. You just need to set the absolute path or use the WP kernel to get the WP downloads file.
Principle:
find a way so that both servers can talk to each other. I used the socket server / client approach. You can do HTTP _POST processor (server) and HTTP _POST maker (client).
Keep a record of the last synchronization time.
At certain intervals, read the folder and write down any files that have changed since the last time synchronization.
Send a list of files that will be updated with the changed time stamp to another server.
He should compare your list with his entries and tell you which of the files he does not have.
Send these files.
The receiver will record files and set the changed date to another on another server. (this is important to avoid endless loops)
Good luck.
source share