纯PHP中远程服务器的镜像文件夹

Tam*_*lyn 6 php rsync sync mirroring

我想让一台机器上的文件夹与另一台机器上的文件夹同步.这是一个WordPress部署插件,所以我不能依赖于任何一台机器上的rsync或其他命令.PHP和Web服务器将在两台机器上都可用,理想情况下它可以通过HTTP工作.

我目前的想法是请求机器将具有最后修改日期的本地文件列表发布到另一台机器上的脚本.另一台机器与其文件进行比较,并使用修改后的文件进行响应 - 要么单独提取文件列表,要么在响应中内联更改的文件.

不过,如果存在,我宁愿使用现有的解决方案.有任何想法吗?

Tam*_*lyn 8

我已经创建了一组简单的类来实现它:https://github.com/outlandishideas/sync

在服务器上,例如example.com/remote.php:

const SECRET = '5ecR3t'; //make this long and complicated
const PATH = '/path/to/source'; //sync all files and folders below this path

$server = new \Outlandish\Sync\Server(SECRET, PATH);
$server->run(); //process the request
Run Code Online (Sandbox Code Playgroud)

在客户端:

const SECRET = '5ecR3t'; //this must match the secret key on the server
const PATH = '/path/to/destination'; //target for files synced from server

$client = new \Outlandish\Sync\Client(SECRET, PATH);
$client->run('http://example.com/remote.php'); //connect to server and start sync
Run Code Online (Sandbox Code Playgroud)