PHPackages                             rairlie/laravel-locking-session - 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. rairlie/laravel-locking-session

ActiveLibrary

rairlie/laravel-locking-session
===============================

Provide session locking in Laravel

v2.0.1(2y ago)90476.8k↑10.2%15[1 PRs](https://github.com/rairlie/laravel-locking-session/pulls)1MITPHPPHP &gt;=7.4CI passing

Since Mar 16Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/rairlie/laravel-locking-session)[ Packagist](https://packagist.org/packages/rairlie/laravel-locking-session)[ RSS](/packages/rairlie-laravel-locking-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (19)Used By (1)

laravel-locking-session
=======================

[](#laravel-locking-session)

This package implements session locking in Laravel by wrapping an exclusive lock around the underlying session driver. As such it should work with any session backend - cookies, files, database, etc. (only files and cookies currently tested).

It addresses the problem where session data is lost due to concurrent requests updating the session at the same time. One instance where this may happen is when making simultaneous XHR requests.

##### Example scenario:

[](#example-scenario)

Consider the case where a variable COUNTER is a value stored in the session, and two requests attempt to increment it at the same time. Without session locking:

```
Request A: Read session data: COUNTER = 1
Request B: Read session data: COUNTER = 1
Request A: COUNTER = COUNTER + 1
Request B: COUNTER = COUNTER + 1
Request A: Write session data: COUNTER = 2
Request B: Write session data: COUNTER = 2

```

Final result: COUNTER = 2

With session locking in place, this becomes:

```
Request A: Lock session
Request A: Read session data: COUNTER = 1
Request B: Attempt to lock session - already locked, must wait
Request A: COUNTER = COUNTER + 1
Request A: Write session data: COUNTER = 2
Request A: Release lock
Request B: Acquires lock
Request B: Read session data: COUNTER = 2
Request B: COUNTER = COUNTER + 1
Request B: Write session data: COUNTER = 3
Request B: Release lock

```

Final result: COUNTER = 3

Session locking ensures correctness at the cost of effectively serialising concurrent requests accessing the session. If you have some concurrent requests that don't use the session, disabling session middleware on those requests allows them to still be concurrent.

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

[](#installation)

```
composer require rairlie/laravel-locking-session

```

In your Laravel app, edit config/app.php and replace the default session handler with the locking one:

```
config/app.php:
- Illuminate\Session\SessionServiceProvider::class,
+ Rairlie\LockingSession\LockingSessionServiceProvider::class,

```

By default, lock files are written to the system temp dir, in a subdir 'sessionlocks'. You can specify an alternative path with:

```
config/session.php:
'lockfile_dir' => '/path/to/my/lockdir'

```

The directory will be created if it doesn't exist.

Requirements
------------

[](#requirements)

1. Write access to the lock dir
2. POSIX file system locking e.g. \*NIX, Windows (untested).

Compatibility
-------------

[](#compatibility)

Laravel Locking Session VersionPHP Version2.x&gt;=7.41.x5.5 - 8.1

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance53

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 74.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~208 days

Recently: every ~187 days

Total

14

Last Release

1005d ago

Major Versions

1.x-dev → v2.0.02023-01-27

PHP version history (2 changes)v1.0.0PHP &gt;=5.5.9

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec941d9d8db5ace4b26fed68f86aa158f95702af69b88faae1fb669b5a1a1b9d?d=identicon)[rairlie](/maintainers/rairlie)

---

Top Contributors

[![rairlie](https://avatars.githubusercontent.com/u/14072280?v=4)](https://github.com/rairlie "rairlie (32 commits)")[![bytestream](https://avatars.githubusercontent.com/u/1788397?v=4)](https://github.com/bytestream "bytestream (3 commits)")[![liepumartins](https://avatars.githubusercontent.com/u/2070205?v=4)](https://github.com/liepumartins "liepumartins (2 commits)")[![ctranExcopy](https://avatars.githubusercontent.com/u/33037596?v=4)](https://github.com/ctranExcopy "ctranExcopy (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![caelaris](https://avatars.githubusercontent.com/u/15701822?v=4)](https://github.com/caelaris "caelaris (1 commits)")[![rossriley](https://avatars.githubusercontent.com/u/5082?v=4)](https://github.com/rossriley "rossriley (1 commits)")[![whoan](https://avatars.githubusercontent.com/u/7103003?v=4)](https://github.com/whoan "whoan (1 commits)")

---

Tags

laravelsession

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rairlie-laravel-locking-session/health.svg)

```
[![Health](https://phpackages.com/badges/rairlie-laravel-locking-session/health.svg)](https://phpackages.com/packages/rairlie-laravel-locking-session)
```

###  Alternatives

[jenssegers/mongodb-session

A MongoDB session driver for Laravel 4, 5, 6, 7 and 8

76308.1k3](/packages/jenssegers-mongodb-session)[ytake/laravel-couchbase

Couchbase providers for Laravel

3051.9k](/packages/ytake-laravel-couchbase)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)[karriere/state

Laravel package for storing current application state in cache/session

1718.5k](/packages/karriere-state)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
