webimpress/safe-writer

Tool to write files safely, to avoid race conditions

Maintainers

👁 webimpress

Package info

github.com/webimpress/safe-writer

pkg:composer/webimpress/safe-writer

Fund package maintenance!

michalbundyra

Statistics

Installs: 41 976 776

Dependents: 28

Suggesters: 1

Stars: 378

Open Issues: 2

2.2.0 2021-04-19 16:34 UTC

Requires

  • php: ^7.3 || ^8.0

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-2-Clause 9d37cc8bee20f7cb2f58f6e23e05097eab5072e6

race conditionwebimpressfile writersafe writerconcurrent write


README

👁 Unit Tests
👁 Coding Standards
👁 Static Analysis
👁 Coverage Status

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.