Download the PHP package kosadchiy/laravel-parallel-db without Composer

On this page you can find all versions of the php package kosadchiy/laravel-parallel-db. 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-parallel-db

Laravel Parallel DB Queries

CI PHP 8.3+

Parallel SQL queries for Laravel using native async database APIs:

No child processes, no queues, no ReactPHP, Amp, or Swoole.

Status: beta. The package is usable, but APIs and behavior may still evolve and are still being tested in real-world scenarios.

Why

When one request needs multiple independent SQL calls, sequential execution adds latency. This package runs them in parallel on separate DB connections in the same PHP process.

Typical use cases:

This package is most useful when queries are independent, read-heavy, and latency-bound. For tiny queries or cold-start paths, the overhead of extra connections, polling, and result collection can outweigh the benefit and even make the request slower. It is also a poor fit for strongly dependent query chains or workloads that require a shared transaction.

High-level design

Core components

Execution flow

  1. User passes map of queries (Builder, Eloquent, or Closure returning one of them).
  2. Compiler normalizes all inputs to CompiledQuery.
  3. Executor keeps pending/running sets and starts up to maxConcurrency queries on dedicated connections.
  4. Drivers poll readiness (stream_select() for PostgreSQL sockets, mysqli_poll() for MySQL links).
  5. Ready queries are reaped and transformed into QueryResult.
  6. Completed connections are returned to the pool when pooling is enabled.
  7. Executor continues until all queries are finished or timeout is reached.

Laravel versions

Installation

Optional extensions by driver:

Publish config:

Configuration

Usage

Default DB manager path

Accessing collections and models

Using closures

With options

Via specific connection

Result format

Each input key maps to QueryResult:

Connection pooling

Idle async connections are pooled by default and reused across run() calls inside the same PHP process.

Connection pooling is especially useful in long-running environments such as Laravel Octane, where worker processes can reuse async connections across many requests. Keep in mind that the pool is process-local: each worker may retain up to max_idle_per_key idle connections per connection config, so total open connections should be sized with your worker count and database limits in mind.

For long-running workers and higher connection counts, consider a database-side pooler such as PgBouncer for PostgreSQL or ProxySQL for MySQL.

Error behavior

Write-query caveats

Writes are allowed (INSERT/UPDATE/DELETE/DDL), but:

Use parallel writes only when this behavior is acceptable.

Driver notes

PostgreSQL

MySQL

Limitations and controversial points

  1. Async API parity differs between ext-pgsql and ext-mysqli.
  2. The MySQL async path does not use prepared statements; bindings are interpolated with escaping as a transport-level limitation of this approach.
  3. stream_select() has platform limits and FD-scaling caveats for very large sets.
  4. Core results are returned as raw rows, but QueryResult provides explicit toCollection() and toEloquentCollection() helpers for post-processing.
  5. Parallel writes are independent operations, not an atomic group transaction.

Benchmark

Synthetic PostgreSQL benchmark setup:

This benchmark is intentionally synthetic and latency-bound. It is useful for showing when overlapping independent query latency helps, but it should not be read as a universal production speedup claim. Real-world gains depend on query cost, result size, connection overhead, database load, pooling behavior, and maxConcurrency.

Pool settings also affect warm-run results. With the default config, up to 3 idle connections per connection key are retained between runs.

Observed trends from the local test environment:

Suggested benchmark matrix for comparing different latency profiles and scheduler settings:

query latency (ms) maxConcurrency sequential avg ms parallel avg ms speedup x Notes
50 1 310.82 302.87 1.03 Near-sequential control case, as expected
50 2 313.10 181.11 1.73 Noticeable gain with limited parallel fan-out
50 3 309.33 124.23 2.49 Best result so far for this workload on the test environment
50 5 296.44 141.14 2.10 Faster than sequential, but slower than maxConcurrency=3 here
50 7 293.76 176.83 1.66 Higher fan-out regressed on this workload and environment
20 3 158.60 63.87 2.48 Lower-latency workload still benefits strongly at the same sweet spot
20 5 135.65 100.63 1.35 Extra fan-out helps less when per-query latency is shorter
100 3 571.07 225.66 2.53 Strong gain on a more latency-bound workload
100 5 560.07 183.81 3.05 Best result so far; higher fan-out paid off for longer waits
0 5 13.74 59.84 0.23 Tiny queries: connection, polling, and collection overhead dominated

Cold-start overhead looks different and should be measured separately. In the following run, pooling was disabled and warmup=0, so the async path had to pay full connection setup cost. For this kind of cold tiny-query scenario, p50 is more representative than avg, because a single startup outlier can skew the sequential mean.

query latency (ms) maxConcurrency pool warmup sequential p50 ms parallel p50 ms speedup x Notes
0 3 off 0 13.78 151.27 0.09 Cold tiny-query path was dominated by connection setup and async transport overhead

Cold-start threshold sweep for the same environment (pool=off, warmup=0, maxConcurrency=3):

query latency (ms) sequential p50 ms parallel p50 ms Notes
0 13.78 151.27 Parallel overhead dominated
5 47.58 168.23 Parallel overhead still dominated
20 132.91 200.12 Parallel was still slower on the cold path
50 286.02 257.41 Cold-start overhead started to pay off
100 565.02 376.12 Strong cold-path win on a latency-bound workload

Takeaway from these synthetic benchmarks:

Testing

Unit tests cover:

Run:

Integration tests cover:

Run:

Notes:


All versions of laravel-parallel-db with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-ctype Version *
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.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 kosadchiy/laravel-parallel-db contains the following files

Loading the files please wait ...