PHPackages                             aihimel/laravel-waiting-request - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. aihimel/laravel-waiting-request

ActiveLibrary[Queues &amp; Workers](/categories/queues)

aihimel/laravel-waiting-request
===============================

A simple implementation for holding request untill a job or background process is done.

v2.0.0(2mo ago)251[2 issues](https://github.com/aihimel/laravel-waiting-request/issues)GPL-3.0-or-laterPHPCI passing

Since May 13Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/aihimel/laravel-waiting-request)[ Packagist](https://packagist.org/packages/aihimel/laravel-waiting-request)[ RSS](/packages/aihimel-laravel-waiting-request/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (13)Used By (0)

Laravel Waiting Request
=======================

[](#laravel-waiting-request)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0650c427396d775fc3a9a56e3ab0466f27f1125427e4bd349adb4df727e8674/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616968696d656c2f6c61726176656c2d77616974696e672d726571756573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aihimel/laravel-waiting-request)[![Total Downloads](https://camo.githubusercontent.com/192eb30d706c5f8c621f9a3fddb87057da561c099e5bbff51c71b3c32032412f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616968696d656c2f6c61726176656c2d77616974696e672d726571756573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aihimel/laravel-waiting-request)[![PHP Version](https://camo.githubusercontent.com/ac3c18587c38afc3f3f5e2f7de23c856c05d54134dbb5171e7ad2a56052e511c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532302d2d253230382e342d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/)[![Laravel Version](https://camo.githubusercontent.com/66d0e9940eb5cc000f57fbb29af1f42cd735acb1e51ab8f8994efc3fedaa5f7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e782532302d2d25323031332e782d4646324432303f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com/)[![Tests](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpunit.yml/badge.svg)](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpunit.yml)[![Check Style](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpcs.yml/badge.svg)](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpcs.yml)[![PHPStan](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpstan.yml/badge.svg)](https://github.com/aihimel/laravel-waiting-request/actions/workflows/phpstan.yml)[![Security](https://github.com/aihimel/laravel-waiting-request/actions/workflows/security.yml/badge.svg)](https://github.com/aihimel/laravel-waiting-request/actions/workflows/security.yml)[![codecov](https://camo.githubusercontent.com/58d7eb59e8f204069d47e25c6ffa0d677e3782a3fcabb5a44bd0e9da702d1e7f/68747470733a2f2f636f6465636f762e696f2f67682f616968696d656c2f6c61726176656c2d77616974696e672d726571756573742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/aihimel/laravel-waiting-request)

A simple implementation for holding requests until a job or background process is finished. This package allows you to conditionally block requests and wait for them to be unblocked within a specified timeout.

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

[](#installation)

You can install the package via composer:

```
composer require aihimel/laravel-waiting-request
```

Configuration
-------------

[](#configuration)

You can publish the configuration file using:

```
php artisan vendor:publish --tag="waiting-request-config"
```

The published configuration file `config/waiting-request.php` contains the following defaults:

```
return [
    'cache_prefix' => env('LW_REQUEST_CACHE_PREFIX', 'lw_request_'),
    'timeout' => env('LW_REQUEST_MAX_WAITING_TIME', 5), // Default whenResolved timeout, in seconds
    'check_interval' => env('LW_REQUEST_CHECK_INTERVAL', 250), // whenResolved poll interval, in milliseconds
    'max_blocking_time' => env('LW_REQUEST_MAX_BLOCKING_TIME', 10), // Default blocker lifetime, in seconds
];
```

KeyEnvPurpose`cache_prefix``LW_REQUEST_CACHE_PREFIX`Prepended to every cache key the package writes.`timeout``LW_REQUEST_MAX_WAITING_TIME`How long `whenResolved()` waits before giving up.`check_interval``LW_REQUEST_CHECK_INTERVAL`How often `whenResolved()` polls between checks.`max_blocking_time``LW_REQUEST_MAX_BLOCKING_TIME`Default lifetime of a blocker. After this many seconds, the next `isBlocked()` / `whenResolved()` call evicts the blocker and emits a warning log.Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

Suppose you have a resource that is being processed in the background (e.g., a large PDF generation or a data sync). You can block requests for this resource until the process is complete.

#### 1. Add a Blocker

[](#1-add-a-blocker)

In your controller or job where the background process starts:

```
use Aihimel\LaravelWaitingRequest\Facades\LWRequest;

LWRequest::addBlocker(User::class, $user->id);

// Optionally override the lifetime (in seconds) per call.
// Non-positive values fall back to the `max_blocking_time` config default.
LWRequest::addBlocker(User::class, $user->id, 30);
```

#### 2. Wait for Resolution

[](#2-wait-for-resolution)

In the request that needs to wait for the resource:

```
use Aihimel\LaravelWaitingRequest\Facades\LWRequest;

// This will wait until the blocker is removed or the timeout is reached
$resolved = LWRequest::whenResolved(User::class, $user->id);

if ($resolved) {
    // Process the request
} else {
    // Handle timeout
}
```

#### 3. Resolve the Blocker

[](#3-resolve-the-blocker)

When the background process is finished:

```
use Aihimel\LaravelWaitingRequest\Facades\LWRequest;

LWRequest::resolveBlocker(User::class, $user->id);
```

Calling `resolveBlocker()` explicitly is still the recommended path — it releases the lock immediately so waiting requests can proceed and avoids the warning log emitted by the auto-expiry backstop (see below).

### Checking if Blocked

[](#checking-if-blocked)

You can also check if a resource is currently blocked without waiting:

```
if (LWRequest::isBlocked(User::class, $user->id)) {
    // Resource is blocked
}
```

> **Note:** `isBlocked()` is **not** a pure read. If the blocker has passed its expiry, this call also forgets the cache entry and emits a `Log::warning`. Avoid placing it on a hot path that you expect to be side-effect-free.

### Blocker Lifetime

[](#blocker-lifetime)

Every blocker now has a finite lifetime.

- The lifetime defaults to `max_blocking_time` from the config (10 seconds out of the box).
- You can override it per call via the third argument to `addBlocker()`.
- When the lifetime is reached, the next `isBlocked()` (and therefore `whenResolved()`) call:
    1. Deletes the cache entry, and
    2. Emits `Log::warning('Waiting-request blocker expired without being resolved', [...])` with `class_path`, `resource_id`, and `expired_at` in the context.

The log line goes through Laravel's `Log` facade, so it honors whatever channel and formatter your app has configured in `config/logging.php`.

If you have a background job that may take longer than 10 seconds, raise `LW_REQUEST_MAX_BLOCKING_TIME` (or pass an explicit TTL to `addBlocker()`) — otherwise the blocker will be auto-released while your job is still running, defeating the purpose of the lock.

Upgrading
---------

[](#upgrading)

### From 1.x to 2.x

[](#from-1x-to-2x)

Version 2.x changes how blockers expire. The public method signatures stay backwards-compatible, but the runtime behavior changes:

- **Blockers now expire automatically.** In 1.x, a blocker lived in cache until `resolveBlocker()` was called. In 2.x, every blocker has a finite lifetime (default 10s, configurable via `LW_REQUEST_MAX_BLOCKING_TIME`). If your job can exceed that, set the env or pass a per-call TTL.
- **`isBlocked()` has side effects.** It deletes expired entries and emits a `Log::warning`.
- **The cache value shape changed** from `true` to a Unix expiry timestamp. Any pre-upgrade blocker keys left in cache will be read as integer `1`, treated as already-expired, deleted, and logged on first access. **Flush the cache (or at least the keys under `cache_prefix`) when deploying the upgrade** to avoid a one-time burst of warning logs and stale-blocker side effects.

See [`CHANGELOG.md`](CHANGELOG.md) for the full change list.

Features &amp; Bug Fixes
------------------------

[](#features--bug-fixes)

If you find any bugs or have a feature request, please [create an issue](https://github.com/aihimel/laravel-waiting-request/issues) on GitHub.

Contributing
------------

[](#contributing)

We welcome contributions! To become a contributor:

1. **Fork** the repository.
2. **Clone** your fork to your local machine.
3. **Create a branch** for your feature or bug fix.
4. **Commit** your changes with descriptive messages.
5. **Push** your branch to your fork.
6. **Submit a Pull Request** to the main repository.

### Local Development

[](#local-development)

This package comes with a Docker-based development environment.

#### Build container

[](#build-container)

```
docker compose --build
```

#### Run automated tests

[](#run-automated-tests)

```
docker exec laravel_waiting_request_app ./vendor/bin/phpunit
```

#### Run PHPCS code inspection

[](#run-phpcs-code-inspection)

```
docker exec laravel_waiting_request_app ./vendor/bin/phpcs
```

#### Run PHPCBF auto-fixer

[](#run-phpcbf-auto-fixer)

```
docker exec laravel_waiting_request_app ./vendor/bin/phpcbf
```

License
-------

[](#license)

The GPL-3.0-or-later License. Please see [License File](LICENSE) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance67

Regular maintenance activity

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~3 days

Total

4

Last Release

63d ago

Major Versions

v1.0.2 → v2.0.02026-05-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3406645?v=4)[Aftabul Islam](/maintainers/aihimel)[@aihimel](https://github.com/aihimel)

---

Top Contributors

[![aihimel](https://avatars.githubusercontent.com/u/3406645?v=4)](https://github.com/aihimel "aihimel (67 commits)")

---

Tags

requestphplaravelpackagebackendblockingwaiting

###  Code Quality

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/aihimel-laravel-waiting-request/health.svg)

```
[![Health](https://phpackages.com/badges/aihimel-laravel-waiting-request/health.svg)](https://phpackages.com/packages/aihimel-laravel-waiting-request)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M9.2k](/packages/larastan-larastan)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

45955.7k](/packages/harris21-laravel-fuse)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15118.7k4](/packages/calebdw-larastan)[iamfarhad/laravel-rabbitmq

Native ext-amqp RabbitMQ queue driver for Laravel production workloads with connection pooling, publisher confirms, Horizon support, Octane support, quorum queues, and high-performance workers

3319.5k](/packages/iamfarhad-laravel-rabbitmq)

PHPackages © 2026

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