Download the PHP package bensedev/laravel-inflight-query-lock without Composer

On this page you can find all versions of the php package bensedev/laravel-inflight-query-lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-inflight-query-lock

Laravel Inflight Query Lock

Latest Version on Packagist Total Downloads

Deduplicate concurrent identical queries using distributed locks and async execution. When multiple requests trigger the same slow query simultaneously, only one executes while others wait for the cached result.

Origin Story

This package was born out of necessity during numerous migration projects where we encountered heavy database queries that couldn't be easily optimized through traditional means like pagination or query simplification. Time and resource constraints forced creative solutions, and this approach proved effective in production environments. Rather than keeping this solution to ourselves, we're sharing it with the community in hopes it helps others facing similar challenges.

The Problem

Imagine 100 concurrent requests all hitting an analytics dashboard that runs the same expensive query:

Result: 100 identical queries hammer your database, causing:

The Solution

With Inflight Query Lock:

Result:

Features

Requirements

Installation

Install via Composer:

Publish the configuration file:

Configuration

Configure in config/inflight-query-lock.php:

Environment Variables

Add to your .env:

Usage

With Eloquent Models

Add the trait to your model:

Use the inflight() method in queries:

Use Cases

1. Analytics Dashboards

2. Report Generation

3. Public API Endpoints

4. Admin Panels

How It Works

  1. Query Hash Generation: Creates unique hash from SQL + bindings + connection
  2. Cache Check: Looks for existing cached result
  3. Lock Acquisition: Attempts to acquire distributed lock
  4. Async Execution: If lock acquired, dispatches job to execute query
  5. Polling: Requests poll cache until result is available
  6. Result Distribution: All requests receive the same cached result

Sequence Diagram

Best Practices

1. Choose Appropriate TTL

2. Use Dedicated Queue

3. Enable Logging During Development

Monitor logs for:

4. Monitor Queue Workers

Ensure queue workers are running:

Use Horizon for monitoring:

Performance Considerations

When to Use

Good candidates:

Avoid for:

Overhead

Testing

Run PHPStan:

Format code:

Troubleshooting

Queries not being cached

  1. Check Redis connection
  2. Verify queue workers are running
  3. Enable logging to debug
  4. Check cache_store configuration

Timeout errors

Increase lock timeout:

High poll overhead

Adjust poll interval:

Changelog

Please see CHANGELOG for recent changes.

Contributing

Contributions are welcome! Please see CONTRIBUTING for details.

Security

If you discover any security issues, please report them via the GitHub issue tracker with the "security" label.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-inflight-query-lock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/support Version ^12.0
illuminate/database Version ^12.0
illuminate/queue Version ^12.0
illuminate/cache Version ^12.0
illuminate/contracts Version ^12.0
bensedev/type-guard Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bensedev/laravel-inflight-query-lock contains the following files

Loading the files please wait ...