Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Locking Session

Laravel Locking Session Laravel Package

rairlie/laravel-locking-session

Laravel package for locking user sessions to a single device or browser, preventing concurrent logins and duplicate active sessions. It helps secure accounts by enforcing one active session per user with configurable middleware and session handling.

View on GitHub
Deep Wiki
Context7

Provide session locking in Laravel

Frequently asked questions about Laravel Locking Session
What does the rairlie/laravel-locking-session package actually do?
It adds session locking to Laravel so that requests sharing the same session ID are serialized rather than racing each other. It also lets you enforce a single active session per user, so a second device or browser login cannot silently create a duplicate session. The package works at the framework seam via configurable middleware and session handling, so it does not require changes to your models or business logic.
How do I install and configure laravel-locking-session in a Laravel app?
The expected flow is a standard Composer require, an auto-discovered service provider, and a published config file. You then opt in by registering the middleware or decorating the session handler, depending on whether you want per-request locking or single-session enforcement. There are no schema changes or data migrations, so the integration should be reversible by removing the config and middleware.
Which Laravel and PHP versions does this package support?
The last tagged release was in August 2023, and Laravel 11 and 12 compatibility is unverified in the current evaluation. Check the composer.json constraints and run your test suite on your target versions before committing. On a Laravel 11 or 12 codebase you may need a small fork or patch, which turns a days-long integration into a week-plus of work plus an internal maintenance line item.
Which session drivers does laravel-locking-session work with?
The package targets Laravel's standard session handling, but the practical requirement is an atomic, shared lock store behind it. The cookie driver is the notable edge case, since session data lives client-side and there is no server-side record to lock around. Confirm support for file, database, redis, and array drivers against the source before relying on it in production.
Should I use Redis, Memcached, or the database as the lock store?
Redis is the natural pairing because it offers atomic locks, low latency, and a store shared across all application nodes. Memcached, DynamoDB, or a database-backed lock also work, but a per-node store degrades the guarantee to single-server only. Remember that whichever store you pick becomes a request-critical dependency, so plan for its failure mode.
Does the package block and wait on lock contention, or fail fast?
The behavior depends on configuration: blocking serializes contending requests so the second waits for the first to finish, while fail-fast returns an error immediately. You should verify whether the wait timeout is configurable and what the caller actually receives on timeout, whether that is a 429, a 500, or a silent bypass. Test this explicitly, because it determines the worst-case user-facing stall time.
Is the lock released if a request throws an exception or hits a fatal error?
A well-behaved implementation releases on exception and on terminate(), and ideally registers a shutdown function as a safety net for fatals and PHP timeouts. If a worker is killed or a deploy interrupts a request between acquire and release, the lock persists until its TTL expires. Set the TTL above your maximum request duration with margin, since that trade-off directly sets the longest possible user stall.
Will session locking slow down my SPA that fires parallel AJAX requests on page load?
Yes, potentially, because requests from the same session are serialized, converting parallel latency into queue time. For an SPA issuing five to ten parallel calls on first load, measure the impact against p95 and p99 latencies rather than averages. Also check whether the package locks the whole request or only the write phase, since whole-request locking is simpler but materially more expensive.
Does laravel-locking-session work with Laravel Octane or Swoole?
Compatibility with Octane and Swoole long-lived workers is not verified, and it must be tested for state leaking across requests. Lock state should live in the shared cache store rather than in worker memory, and any per-request flags must be reset between jobs. Run a concurrency test under Octane before deploying, and watch for self-deadlock when internal sub-requests re-enter the app with the same session cookie.
Is this package actively maintained, and what are the alternatives?
It has roughly 91 stars, a single maintainer, and its last release was August 2023, so treat it as a small forkable utility rather than a supported product. That is acceptable given the small code volume, but it should be an explicit decision with an owner on your team. Alternatives include building a narrow cache lock middleware yourself or using Laravel's built-in atomic locks via Cache::lock around session writes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections