~/docs
Resonate
Resonate
13.x 13.43.0.3, current
Fledge Fiber
Toggle sidebar
Fledge Fiber
webpatser/fledge-fiber 13.43.0.3

Fledge Fiber 13.x

Quick Start

Switch the database and Redis drivers to the Fledge async drivers and run work concurrently in fibers.

Pick the drivers

Set the drivers in your .env:

DB_CONNECTION=fledge-mysql
REDIS_CLIENT=fledge
Driver Database
fledge-mysql MySQL
fledge-mariadb MariaDB
fledge-pgsql PostgreSQL

The Redis client is selected with REDIS_CLIENT=fledge.

Run work concurrently

async() starts a closure in a new fiber and returns a Future; await() waits for the result. disperse() runs several closures concurrently and returns their results in input order.

use function Fledge\Async\async;
use function Fledge\Async\disperse;
 
$future = async(function (): string {
// non-blocking I/O here
return 'done';
});
 
$result = $future->await();
 
$results = disperse([
'first' => fn () => 1,
'second' => fn () => 2,
]);

If a closure throws, disperse() throws a CompositeException holding the errors.

Transactions and fibers

On fledge-mysql, fledge-mariadb and fledge-pgsql, transactions are pinned per Laravel connection, not per fiber. While one fiber has a transaction open, a query, execute, begin, commit or rollback from another fiber on the same connection throws a LogicException. Give concurrent fibers separate connections.

Guzzle on the Fledge handler

FiberHttpServiceProvider registers FledgeHandler, a Guzzle handler backed by the async HTTP client, globally (it is disabled under PHPUnit). Opt out at runtime with Factory::globalHandler(null).

Mail, Pusher/Reverb broadcasting, S3 and Elasticsearch traffic also goes through Fledge by default. See Examples for the flags that turn each one off.