PHPackages                             ivopetkov/lock - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ivopetkov/lock

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ivopetkov/lock
==============

Locks library for PHP

v1.4.0(5mo ago)713.1k21MITPHPPHP 8.0.\*|8.1.\*|8.2.\*|8.3.\*|8.4.\*|8.5.\*

Since May 27Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/ivopetkov/lock)[ Packagist](https://packagist.org/packages/ivopetkov/lock)[ Fund](https://www.paypal.me/ivopetkovcom)[ GitHub Sponsors](https://github.com/ivopetkov)[ RSS](/packages/ivopetkov-lock/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (1)Versions (15)Used By (1)

Lock
====

[](#lock)

A simple locking library ... that is based on file locking (and that's awesome).

[![Latest Stable Version](https://camo.githubusercontent.com/826e38b412b61699c6b34f9a5310f9fd4dc658960bdc825876e13f3748214d69/68747470733a2f2f706f7365722e707567782e6f72672f69766f7065746b6f762f6c6f636b2f762f737461626c65)](https://packagist.org/packages/ivopetkov/lock)[![License](https://camo.githubusercontent.com/25f80a34f366566f4d55324b7f3de4619d655c238ead06b33bf7db5aa9b87dda/68747470733a2f2f706f7365722e707567782e6f72672f69766f7065746b6f762f6c6f636b2f6c6963656e7365)](https://packagist.org/packages/ivopetkov/lock)

Why you need it
---------------

[](#why-you-need-it)

Imagine you have two tasks that you do not want to overlap (they modify the same data for example). Using this library will bring you peace of mind.

Keep in mind
------------

[](#keep-in-mind)

The library uses file locking mechanism to ensure it works correctly. This means that it can be used only on applications/instances/processes that share a common file system. A website on one server does just that.

Install via Composer
--------------------

[](#install-via-composer)

```
composer require ivopetkov/lock
```

Usage
-----

[](#usage)

Using the following two methods (acquire() and release()) will ensure no two applications/instances/processes execute the code between them.

```
