Skip to content
Synchronise two directories.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
bin
src
test/unit
.gitignore
.scrutinizer.yml
README.md
composer.json
composer.lock

README.md

Synchronise two directories.

rsync is the tool of choice for ensuring that two directories have the same content, but is only present by default on Unix systems. This repository provides simple recursive directory synchronisation in plain PHP, compatible on Linux, Mac and Windows.


Build status Code quality Code coverage Current version PHP.Gt/Sync documentation

Example usage

$source = "/var/www/example.com";
$destination = "/var/backup/example.com";

try {
	$sync = new DirectorySync($source, $destination);
	$sync->exec(DirectorySync::COMPARE_FILEMTIME);
}
catch(SyncException $exception) {
	fwrite(STDERR, "Error performing sync: " . $exception->getMessage());
	exit(1);
}

echo "Sync complete!" . PHP_EOL;
echo "Changed: " . count($sync->getCopiedFilesList());
echo "Deleted: " . count($sync->getDeletedFilesList());
echo "Skipped: " . count($sync->getSkippedFilesList());

Features

  • Cross-platform compatible directory synchronisation (Linux, Windows, Mac).
  • Selective sync through glob matches (only sync js files within script directory with /script/**/*.js).
  • Get statistics of copied/deleted/skipped files after sync execution.
  • Low memory footprint.
You can’t perform that action at this time.