webimpress / safe-writer
Tool to write files safely, to avoid race conditions
Fund package maintenance!
michalbundyra
Installs: 30 985 326
Dependents: 26
Suggesters: 0
Security: 0
Stars: 376
Watchers: 7
Forks: 9
Open Issues: 3
Requires
- php: ^7.3 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5.4
- vimeo/psalm: ^4.7
- webimpress/coding-standard: ^1.2.2
This package is auto-updated.
Last update: 2024-12-05 16:19:37 UTC
README
Write files safely to avoid race conditions when the same file is written multiple times in a short time period.
Installation
Using composer:
composer require webimpress/safe-writer
Usage
use Webimpress\SafeWriter\FileWriter; $targetFile = __DIR__ . '/target-file.php'; $content = "<?php\nreturn " . var_export($data, true) . ';'; FileWriter::writeFile($targetFile, $content);
If something goes wrong exception (instance of Webimpress\SafeWriter\Exception\ExceptionInterface
)
will be thrown.