Write files safely, to avoid race conditions
Write files safely to avoid race conditions when the same file is written multiple times in a short time period.
$ composer require webimpress/safe-writer
$targetFile = DIR . '/target-file.php'; $content = "<?php \nreturn " . var_export($data, true) . ';';
If something goes wrong exception (instance of
Webimpress\SafeWriter\Exception\ExceptionInterface) will be thrown.