Documentation Packages Support

Parallel β‹… Parallel processing for PHP

This package provides true parallel processing for PHP using multiple processes or native threads, without blocking and no extensions required.


This package can be installed as a Composer dependency.

composer require amphp/parallel


The basic usage of this library is to submit blocking tasks to be executed by a worker pool in order to avoid blocking the main event loop.


require __DIR__ . '/../vendor/autoload.php';

use Amp\Parallel\Worker;
use Amp\Promise;

$urls = [

$promises = [];
foreach ($urls as $url) {
    $promises[$url] = Worker\enqueueCallable('file_get_contents', $url);

$responses = Promise\wait(Promise\all($promises));

foreach ($responses as $url => $response) {
    \printf("Read %d bytes from %s\n", \strlen($response), $url);

file_get_contents is just used as an example for a blocking function here. If you just want to fetch multiple HTTP resources concurrently, it’s better to use Artax, our non-blocking HTTP client.

The functions you call must be predefined or autoloadable by Composer so they also exist in the worker processes. Instead of simple callables, you can also enqueue Task instances with Amp\Parallel\Worker\enqueue().