PHPackages                             webimpress/safe-writer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. webimpress/safe-writer

ActiveLibrary[File &amp; Storage](/categories/file-storage)

webimpress/safe-writer
======================

Tool to write files safely, to avoid race conditions

2.2.0(5y ago)37839.9M—2.8%9[1 issues](https://github.com/webimpress/safe-writer/issues)[1 PRs](https://github.com/webimpress/safe-writer/pulls)20BSD-2-ClausePHPPHP ^7.3 || ^8.0CI failing

Since Nov 15Pushed 4w ago4 watchersCompare

[ Source](https://github.com/webimpress/safe-writer)[ Packagist](https://packagist.org/packages/webimpress/safe-writer)[ GitHub Sponsors](https://github.com/michalbundyra)[ RSS](/packages/webimpress-safe-writer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (12)Used By (20)

Webimpress Safe Writer
======================

[](#webimpress-safe-writer)

[![Unit Tests](https://github.com/webimpress/safe-writer/actions/workflows/phpunit.yml/badge.svg)](https://github.com/webimpress/safe-writer/actions/workflows/phpunit.yml)[![Coding Standards](https://github.com/webimpress/safe-writer/actions/workflows/phpcs.yml/badge.svg)](https://github.com/webimpress/safe-writer/actions/workflows/phpcs.yml)[![Static Analysis](https://github.com/webimpress/safe-writer/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/webimpress/safe-writer/actions/workflows/static-analysis.yml)[![Coverage Status](https://camo.githubusercontent.com/0f2f1c3a64d827cbb21cb9923f693f6afb8b00b2808c4c20a21d4c25ebe90f7f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f776562696d70726573732f736166652d7772697465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/webimpress/safe-writer?branch=master)

Write files safely to avoid race conditions when the same file is written multiple times in a short time period.

Installation
------------

[](#installation)

Using composer:

```
composer require webimpress/safe-writer
```

Usage
-----

[](#usage)

```
use Webimpress\SafeWriter\FileWriter;

$targetFile = __DIR__ . '/target-file.php';
$content = "
