PHPackages                             xman12/single-flight - 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. xman12/single-flight

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

xman12/single-flight
====================

Single Flight library - prevents duplicate execution of the same operation

1.0.0(4mo ago)03MITPHPPHP &gt;=8.1

Since Feb 10Pushed 4mo agoCompare

[ Source](https://github.com/xman12/single-flight)[ Packagist](https://packagist.org/packages/xman12/single-flight)[ RSS](/packages/xman12-single-flight/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Single Flight PHP Library
=========================

[](#single-flight-php-library)

A library for preventing duplicate execution of identical operations in PHP with support for various storage backends (Memory, Redis).

Description
-----------

[](#description)

Single Flight is a pattern that ensures the same operation (e.g., database query or external API request) executes only once, even if multiple processes or threads request it simultaneously. Other requests will wait for the result of the first execution.

### Key Features

[](#key-features)

- Prevention of duplicate operations
- Inter-process synchronization
- Support for various storage backends (Memory, Redis)
- TTL (Time To Live) for automatic cache expiration
- Result caching between processes via Redis
- Cache stampede prevention

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

[](#installation)

```
composer require xman12/single-flight
```

Usage
-----

[](#usage)

### Basic Example (In-Memory)

[](#basic-example-in-memory)

```
