Rsync

About

Rsync is a pure PHP 7.1+ dependency-free wrapper for rsync client. It provides you a simple way to abstract from command line control rsync right from php. Library uses PSR-4 autoloader standard and always has 100% tests coverage.
There is no need to tell about rsync, except the fact that php doesn't has any faster or equal built-in way to upload files to remote server.

Library supports whole bunch of options and parameters implemented in rsync client version 3.1.2

Why Rsync?

It is small and fully covered with tests It is well documented I'm eating my own sweet pie=) Supports whole bunch of parameters and options of rsync and ssh Easy to use Works on Windows (ofcourse id you installed ssh and rsync clients for Windows)

Requirements

PHP 7.1+ PHP config variables_order must contain E, 4ex: variables_order=EGPCS.
Otherwise you will have to manually specify absolute path to rsync and ssh binaries (at least on Windows) rsync client 3.1.2 +

Installation

Install with composer

composer require xobotyi/rsync

Docs

The code is well documented, for methods and parameters descriptions see the sources.

Usage

Simplest:

use xobotyirsyncRsync; $rsync = new Rsync(); $rsync->sync('/path/to/source', '/path/to/destination');

If you need SSH:

use xobotyirsyncRsync; use xobotyirsyncSSH; $rsync = new Rsync([ Rsync::CONF_CWD => __DIR__, Rsync::CONF_EXECUTABLE => '/even/alternative/executable/rsync.exe', Rsync::CONF_SSH => [ SSH::CONF_EXECUTABLE => '/even/alternative/executable/ssh.exe', SSH::CONF_OPTIONS => [ SSH::OPT_OPTION => ['BatchMode=yes', 'StrictHostKeyChecking=no'], SSH::OPT_IDENTIFICATION_FILE => './path/to/ident', SSH::OPT_PORT => 2222, ], ], ]); $rsync->sync('./relative/path/to/source', 'user@some.remote.lan:/abs/path/to/destination'); echo './relative/path/to/source ' . ($rsync->getExitCode() === 0 ? 'successfully synchronized with remote.' : 'not synchronised due to errors.') . "n"; $rsync->setExecutable('ssh') ->setOption(SSH::OPT_OPTION, false)// 'false' value turns off the options ->setOptions([ SSH::OPT_IDENTIFICATION_FILE => './new/path/to/ident', SSH::OPT_PORT => 22, ]); $rsync->sync('/new/path/to/source', 'user@some.remote.lan:/abs/path/to/destination'); echo '/new/path/to/source ' . ($rsync->getExitCode() === 0 ? 'successfully synchronized with remote.' : 'not synchronised due to errors.') . "n";

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。