Download the PHP package diegobvasco/php-rsync without Composer
On this page you can find all versions of the php package diegobvasco/php-rsync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download diegobvasco/php-rsync
More information about diegobvasco/php-rsync
Files in diegobvasco/php-rsync
Package php-rsync
Short Description A fluent PHP library for building and executing rsync commands
License MIT
Informations about the package php-rsync
A pure-PHP directory synchronization tool inspired by the rsync command. Sync directories by copying new and modified files, removing deleted files, and skipping exclusions — all with a clean fluent API.
Requires PHP 8.5+
Installation
Usage
Basic Sync
With Exclusions
With Delete Mode
With Real-Time Output
Dry Run
Accessing Results
Skip Pattern Syntax
| Pattern | Meaning |
|---|---|
*.log |
All .log files |
vendor/* |
Everything inside vendor/ |
**/*.log |
Any .log file in any subdirectory |
logs/ |
The logs/ directory and all its contents |
??.txt |
Two-character .txt filenames |
[abc].txt |
Files named a.txt, b.txt, or c.txt |
[^ab].log |
Any single-character .log filename except a or b |
How It Works
- Scans the source directory for all files
- Filters out files matching exclusion patterns
- Compares each file's modification time and size against the destination
- Copies only new or changed files
- Deletes destination files that no longer exist in the source (when
delete()is enabled) - Removes empty directories from the destination
- Returns a
Resultobject with full sync details
API
Rsync
The optional Output interface receives callbacks for each file action during sync. A TerminalOutput implementation is included that prints to STDOUT (or a custom stream).
The optional Filesystem argument lets you swap the default LocalFilesystem (which uses PHP's global FS functions) for any other implementation — useful for testing against InMemoryFilesystem or a custom backend. It is backward compatible: new Rsync() and new Rsync($output) keep working unchanged.
Performance: file checksums are computed lazily — the expensive xxh128 hash only runs in
--checksummode (or when you read$file->checksum). The destination tree is scanned only when a delete mode is enabled; otherwise each source file is checked against its destination counterpart individually.
Core
| Method | Description |
|---|---|
copy(string $source, string $destination): self |
Set source and destination directories |
skip(string\|array $patterns): self |
Add glob patterns to exclude from sync |
delete(): self |
Enable delete mode — removes destination files not in source |
recursive(): self |
Enable recursive mode |
archive(): self |
Enable archive mode (equivalent to -rlptgoD) |
run(): Result |
Execute the sync and return results |
toCommand(): string |
Generate equivalent rsync shell command for debugging |
reset(): self |
Reset all flags and options |
Metadata Preservation
| Method | Description |
|---|---|
times(): self |
Preserve modification times (--times) |
perms(): self |
Preserve permissions (--perms) |
owner(): self |
Preserve owner (--owner) |
group(): self |
Preserve group (--group) |
acls(): self |
Preserve ACLs (--acls) |
xattrs(): self |
Preserve extended attributes (--xattrs) |
devices(): self |
Preserve device files (--devices) |
specials(): self |
Preserve special files (--specials) |
numericIds(): self |
Don't map uid/gid values (--numeric-ids) |
Comparison
| Method | Description |
|---|---|
checksum(): self |
Use checksum instead of mod-time & size (--checksum) |
ignoreTimes(): self |
Don't skip files that match size and time (--ignore-times) |
sizeOnly(): self |
Skip files that match size only (--size-only) |
update(): self |
Skip files newer on the receiver (--update) |
Excludes / Includes
| Method | Description |
|---|---|
exclude(string\|array $patterns): self |
Add patterns to exclude (--exclude) |
excludeFrom(string $file): self |
Read exclude patterns from file (--exclude-from) |
excludeDir(string\|array $patterns): self |
Add directory exclusion patterns (--exclude-dir) |
include(string\|array $patterns): self |
Add patterns to include (--include) |
includeFrom(string $file): self |
Read include patterns from file (--include-from) |
pruneEmptyDirs(): self |
Remove empty directories from file list (--prune-empty-dirs) |
Backup
| Method | Description |
|---|---|
backup(): self |
Make backups of changed files (--backup) |
backupDir(string $dir): self |
Set backup directory (--backup-dir) |
suffix(string $suffix): self |
Set backup suffix (--suffix) |
Symlinks / Hardlinks
| Method | Description |
|---|---|
links(): self |
Copy symlinks as symlinks (--links) |
copyLinks(): self |
Transform symlinks to referent files (--copy-links) |
copyUnsafeLinks(): self |
Transform unsafe symlinks to referent files in directories (--copy-unsafe-links) |
safeLinks(): self |
Ignore symlinks that go outside tree (--safe-links) |
hardLinks(): self |
Preserve hard links (--hard-links) |
Size Limits
| Method | Description |
|---|---|
maxSize(int\|string $size): self |
Maximum file size to transfer (--max-size) |
minSize(int\|string $size): self |
Minimum file size to transfer (--min-size) |
Behavior
| Method | Description |
|---|---|
dryRun(): self |
Show what would be done without doing it (--dry-run) |
force(): self |
Force deletion of non-empty directories (--force) |
removeSourceFiles(): self |
Remove source files after successful transfer (--remove-source-files) |
Output
| Method | Description |
|---|---|
verbose(): self |
Verbose output (--verbose) |
quiet(): self |
Suppress output (--quiet) |
progress(): self |
Show progress (--progress) |
stats(): self |
Show statistics (--stats) |
itemizeChanges(): self |
Show itemized changes (--itemize-changes) |
humanReadable(): self |
Human-readable numbers (--human-readable) |
Delete Modes
| Method | Description |
|---|---|
delete(): self |
Delete files in destination not in source (--delete) |
deleteBefore(): self |
Delete before transfer (--delete-before) |
deleteAfter(): self |
Delete after transfer (--delete-after) |
deleteExcluded(): self |
Delete excluded files from destination (--delete-excluded) |
Result
| Method | Description |
|---|---|
copiedCount(): int |
Number of files copied |
deletedCount(): int |
Number of files deleted |
skippedCount(): int |
Number of files skipped |
totalBytesCopied(): int |
Total bytes copied |
totalBytesDeleted(): int |
Total bytes deleted |
summary(): string |
Human-readable summary |
copiedPaths(): array |
List of copied file paths |
deletedPaths(): array |
List of deleted file paths |
skippedPaths(): array |
List of skipped file paths |
FileInfo
| Method | Description |
|---|---|
formattedSize(): string |
Human-readable file size (e.g. "12.5 KB") |
formattedMtime(): string |
ISO 8601 formatted modification time |
Output (interface)
Implement this to receive real-time file action callbacks during sync.
| Method | Description |
|---|---|
copied(FileInfo $file): void |
Called when a file is copied |
deleted(FileInfo $file): void |
Called when a file is deleted |
skipped(FileInfo $file): void |
Called when a file is skipped |
TerminalOutput
Built-in implementation of Output that prints actions to a stream.
Defaults to STDOUT. Pass a custom stream to redirect output:
Filesystem (interface)
Abstraction over all filesystem operations. The default LocalFilesystem wraps PHP's global FS functions; InMemoryFilesystem is a disk-less implementation that is handy for tests:
Quality
This package enforces high code quality standards:
- 100% code coverage via Pest
- 100% type coverage via
pestphp/pest-plugin-type-coverage - PHPStan at max level for static analysis
- Laravel Pint for code style
- Rector for automated refactoring
Changelog
Please see CHANGELOG for more information on recent changes.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of php-rsync with dependencies
ext-hash Version *