Asynchronous cURL library for PHP with reasonable API

v1.0.0 2016-10-29 12:33 UTC

This package is not auto-updated.

Last update: 2024-03-02 16:54:31 UTC


Asynchronous cURL library for PHP with reasonable API.

Build Status Latest stable License

PHP is by default single-thread language but when it comes to HTTP requests it is not very convenient to do them in serial. cURL implementation in PHP offers functions for multi requests but with terrible C-style API. This library wraps those functions into modern object-oriented event-driven API.


async-request/async-request version 1.x requires PHP 7.1+ with cUrl extension enabled.

If you are using PHP5.4+ you can use async-request/async-request version 0.x.


You can easily install the newest version using Composer:

composer require async-request/async-request

Simple example

$urls = [

$asyncRequest = new AsyncRequest\AsyncRequest();

foreach ($urls as $url) {
	$request = new AsyncRequest\Request($url);
	$asyncRequest->enqueue($request, function(AsyncRequest\Response $response) {
		echo $response->getBody() . "\n";


Advanced features

You can specify number of requests that can run in parallel:


You can add other requests in callback function:

$callback = function(AsyncRequest\Response $response, AsyncRequest\AsyncRequest $asyncRequest) {
	$asyncRequest->enqueue(new AsyncRequest\Request(''));

You can specify priority of each request and requests with higher priority will be called first:

$asyncRequest->enqueueWithPriority(10, $request, $callback);

If you want to use some cURL options, it is as easy as this:

$request = new AsyncRequest\Request($url);
$request->setOption(CURLOPT_POST, true);

And if you want some special behavior or some additional data in Response, you can always create your own Request object by implementing IRequest interface.