clue/block-react
Lightweight bridge to run ReactPHP’s event loop in a blocking way. Lets you wait for promises and async operations from synchronous PHP code, ideal for CLI tools and scripts that need occasional async I/O without restructuring your whole app.
Start by installing via Composer: composer require clue/block-react. This library is not a standalone tool—it's a bridge to allow ReactPHP-based async components (like HTTP clients, databases, or sockets) to be used in synchronous, blocking contexts (e.g., CLI scripts, traditional PHP apps, or Laravel jobs). Use it when you want to call async ReactPHP code immediately and synchronously—like echo $loop->run($asyncPromise);. Begin with the Loop class: it manages the ReactPHP event loop for the duration of your blocking call and cleans up afterward.
HttpClient, Filesystem) in a closure passed to Block\run().
use Clue\Block;
$result = Block\run(function () {
$loop = React\EventLoop\Loop::get();
$client = new React\Http\Client($loop);
$promise = $client->get('https://api.example.com/data');
return $promise;
});
handle() or execute() to perform async I/O (e.g., call external APIs, write to Redis) without resorting to pcntl_fork or Guzzle promises in blocking mode.Block\run() inside PHPUnit tests to assert on their results synchronously.Block\run() over manually instantiating Loop—it handles automatic cleanup and reentrant loop behavior.preg_replace_callback with null in subject is deprecated—some older ReactPHP components may trigger this; ensure all dependencies are modern.clue/block-react uses Loop::run() internally, which may cause issues if you manually start another loop elsewhere in the same process (e.g., Laravel Octane + ReactPHP). Avoid overlapping loops.Block\withTimeout() to add safety:
$result = Block\run(function () use ($loop) {
return (new React\Promise\Timer\Timeout::Promise(
$someAsyncOperation(),
5.0,
$loop
));
});
Loop::get() may return a non-reentrant loop—check environment compatibility.Block\run() recursively (e.g., inside a run() callback that itself calls run()) causes deadlocks—avoid this pattern.How can I help you explore Laravel packages today?