PHPackages                             aalfiann/parallel-request-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. aalfiann/parallel-request-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

aalfiann/parallel-request-php
=============================

A PHP class to create multiple request in parallel (non-blocking).

1.4.2(7y ago)1218.1k↓14.3%23MITPHPPHP &gt;=5.4

Since Sep 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/aalfiann/parallel-request-php)[ Packagist](https://packagist.org/packages/aalfiann/parallel-request-php)[ RSS](/packages/aalfiann-parallel-request-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (11)Used By (3)

ParallelRequest PHP
===================

[](#parallelrequest-php)

[![Version](https://camo.githubusercontent.com/74cb70cf32ca8c453ee8d86541478af8e2cef8a39d063b81cbb0d477be83bb41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61616c6669616e6e2f706172616c6c656c2d726571756573742d7068702e737667)](https://packagist.org/packages/aalfiann/parallel-request-php)[![Downloads](https://camo.githubusercontent.com/5570329db639653dc3b1ac6daea97e6e994920e84e47214dea939283e8be6512/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61616c6669616e6e2f706172616c6c656c2d726571756573742d7068702e737667)](https://packagist.org/packages/aalfiann/parallel-request-php)[![License](https://camo.githubusercontent.com/01fc70cb8eb55895498ddd3f21d539a1585daafb98cff2c8278c45aad6a1c137/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61616c6669616e6e2f706172616c6c656c2d726571756573742d7068702e737667)](https://github.com/aalfiann/parallel-request-php/blob/HEAD/LICENSE.md)

A PHP class to create multiple request in parallel (non blocking).

Installation
------------

[](#installation)

Install this package via [Composer](https://getcomposer.org/).

```
composer require "aalfiann/parallel-request-php:^1.0"

```

Usage send GET request
----------------------

[](#usage-send-get-request)

This will send GET request silently without response output.

```
use \aalfiann\ParallelRequest;
require_once ('vendor/autoload.php');

$req = new ParallelRequest;

// You can set request with simple array like this
$req->request = ['https://jsonplaceholder.typicode.com/posts/1','https://jsonplaceholder.typicode.com/posts/2'];

// Or you can set request array with addRequest() function
for($i=1;$iaddRequest('https://jsonplaceholder.typicode.com/posts/'.$i);
}

$req->options = [
    CURLOPT_NOBODY => false,
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
];
$req->send();
```

If you want to see the response

```
echo var_dump($req->send()->getResponse());
```

Usage send POST request
-----------------------

[](#usage-send-post-request)

```
use \aalfiann\ParallelRequest;
require_once ('vendor/autoload.php');

$req = new ParallelRequest;

// You can set post request with array formatted like this
$req->request = [
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts',
            'post' => [
                'title' => 'foo 1',
                'body' => 'bar 1',
                'userId' => 1
            ]
        ],
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts',
            'post' => [
                'title' => 'foo 2',
                'body' => 'bar 2',
                'userId' => 2
            ]
        ]
    ];

// Or you can set request array with addRequest() function
$req->setRequest(array()); //==> cleanup any request first (optional)
for($i=1;$iaddRequest('https://jsonplaceholder.typicode.com/posts',[
        'title' => 'foo '.$i,
        'body' => 'bar '.$i,
        'userId' => $i
    ]);
}

$req->encoded = true;
$req->options = [
    CURLOPT_NOBODY => false,
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
];

echo var_dump($req->send()->getResponse());
```

Usage send for custom request
-----------------------------

[](#usage-send-for-custom-request)

If you want to send custom request like PUT, PATCH, DELETE, etc.
Just add the `CURLOPT_CUSTOMREQUEST => 'PUT'`.

```
use \aalfiann\ParallelRequest;
require_once ('vendor/autoload.php');

$req = new ParallelRequest;

// You can set post request with array formatted like this
$req->request = [
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts/1',
            'post' => [
                'id' => 1,
                'title' => 'foo 1',
                'body' => 'bar 1',
                'userId' => 1
            ]
        ],
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts/2',
            'post' => [
                'id' => 2,
                'title' => 'foo 2',
                'body' => 'bar 2',
                'userId' => 1
            ]
        ]
    ];

// Or you can set request array with addRequest() function
$req->setRequest(array()); //==> cleanup any request first (optional)
for($i=1;$iaddRequest('https://jsonplaceholder.typicode.com/posts/'.$i,[
        'id' => $i,
        'title' => 'foo '.$i,
        'body' => 'bar '.$i,
        'userId' => $i
    ]);
}

$req->encoded = true;
$req->options = [
    CURLOPT_NOBODY => false,
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_CUSTOMREQUEST => 'PUT'
];

echo var_dump($req->send()->getResponse());
```

Chain Usage
-----------

[](#chain-usage)

You also able to make chain.

```
use \aalfiann\ParallelRequest;
require_once ('vendor/autoload.php');

$req = new ParallelRequest;

// example simple request
echo $req->setRequest('http://jsonplaceholder.typicode.com/posts')->send()->getResponse();

// example complicated request
echo var_dump($req->
    ->setRequest(array()) //==> cleanup any request first (optional)
    ->addRequest('https://jsonplaceholder.typicode.com/posts',[
        'title' => 'foo 1',
        'body' => 'bar 1',
        'userId' => 1
    ])
    ->addRequest('https://jsonplaceholder.typicode.com/posts/1')
    ->addRequest('https://jsonplaceholder.typicode.com/posts',[
        'title' => 'foo 2',
        'body' => 'bar 2',
        'userId' => 2
    ])
    ->addRequest('https://jsonplaceholder.typicode.com/posts',[
        'userId' => 3
    ],false)
    ->setOptions([
        CURLOPT_NOBODY => false,
        CURLOPT_HEADER => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false
    ])
    ->setEncoded()->setHttpInfo()->send()->getResponse());
```

How to debug
------------

[](#how-to-debug)

To send a request absolutely we need to know what happened in our request

```
// to see the detail of request
$req->httpInfo = 'detail';

// or use chain function like this
$req->setHttpInfo('detail')

// or if you want only http code info
$req->setHttpInfo()
```

Difference setRequest() and addRequest() and addRequestRaw()
------------------------------------------------------------

[](#difference-setrequest-and-addrequest-and-addrequestraw)

This three functions are required to build the request.

`setRequest()` is need you to create the string / formatted array first before use this.
Example:

```
// build the formatted array first.
// You are able to create more complex form-data or raw data.
$request = [
        'https://jsonplaceholder.typicode.com/posts/1',
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts/2',
            'post' => [
                'title' => 'foo 2',
                'body' => 'bar 2',
                'userId' => 2
            ]
        ],
        [
            'url' => 'https://jsonplaceholder.typicode.com/posts',
            'post' => json_encode([
                'title' => 'foo 3',
                'body' => 'bar 3',
                'userId' => 3
            ])
        ]
    ];

// then you can use setRequest() function
$req->setRequest($request);
```

`addRequest()` is you can create string / formatted array on the fly
Example:

```
// url only
$req->addRequest('https://jsonplaceholder.typicode.com/posts/1');

// send request with form-data
$req->addRequest('https://jsonplaceholder.typicode.com/posts',[
        'title' => 'foo 2',
        'body' => 'bar 2',
        'userId' => 2
    ]);

// send request with data parameter on url
$req->addRequest('https://jsonplaceholder.typicode.com/posts',[
        'userId' => 3
    ],false);
```

`addRequestRaw()` is you can create raw data to send through request
Example:

```
// url with raw json data
// setEncoded(true) or $req->encoded = true will not work, so you have to encoded this by yourself
$req->addRequestRaw('https://jsonplaceholder.typicode.com/posts',json_encode([
        'title' => 'foo 2',
        'body' => 'bar 2',
        'userId' => 2
    ]));

// http header is required to send raw json data
$req->options = [
    CURLOPT_NOBODY => false,
    CURLOPT_HEADER => false,
    CURLOPT_HTTPHEADER => ['Content-type: application/json; charset=UTF-8'],
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
];
```

Function List
-------------

[](#function-list)

- **setRequest($request)** is to create the request url (string or array with post data).
- **addRequest($url,$params=array(),$formdata=true)** is to create the request url (string or array with params data).
- **addRequestRaw($url,$data)** is to create the request url with raw data formatted. Parameter data is not encoded by default.
- **setOptions($options=array())** is to set the options of CURLOPT.
- **setHttpStatusOnly($httpStatusOnly=false)** if set to true then output response will converted to http status code.
- **setHttpInfo($httpInfo=false)** if set to true then output response will display the http info status. Set to "detail" for more info.
- **setDelayTime($time=10000)** is the delay execution time for cpu to take a rest. Default is 10000 (10ms) in microseconds.
- **setEncoded($encoded=true)** is to encode the data post. The default data post is not encoded so you can create more complex data request.
- **send()** is curl are sending the request (silently without any output)
- **getResponse()** is to get the output response (the return data could be string or array).
- **getResponseJson()** is to get the output response with json formatted.

**Note:**

- If you only create single request, response will return string.
- This class basically using `curl_multi_exec()` function.
- If you not specify `$req->options` then it will be use `[CURLOPT_HEADER => false,CURLOPT_RETURNTRANSFER => true]` as default.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~27 days

Recently: every ~8 days

Total

10

Last Release

2565d ago

PHP version history (2 changes)1.0.0PHP ^5.4

1.0.3PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c101f6be505e4713be942f6b80d849b46702e6f4069430e1dbbe60fa18289c54?d=identicon)[aalfiann](/maintainers/aalfiann)

---

Top Contributors

[![aalfiann](https://avatars.githubusercontent.com/u/9458941?v=4)](https://github.com/aalfiann "aalfiann (16 commits)")

---

Tags

requestasyncnon-blockingcurlparallel

### Embed Badge

![Health badge](/badges/aalfiann-parallel-request-php/health.svg)

```
[![Health](https://phpackages.com/badges/aalfiann-parallel-request-php/health.svg)](https://phpackages.com/packages/aalfiann-parallel-request-php)
```

###  Alternatives

[amphp/http-server

A non-blocking HTTP application server for PHP based on Amp.

1.3k4.5M81](/packages/amphp-http-server)[amphp/http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.

7296.8M137](/packages/amphp-http-client)[amphp/websocket-client

Async WebSocket client for PHP based on Amp.

1623.0M39](/packages/amphp-websocket-client)[aplus/http-client

Aplus Framework HTTP Client Library

2161.6M1](/packages/aplus-http-client)[khr/php-mcurl-client

wrap curl client (http client) for PHP 5.3; using php multi curl, parallel request and write asynchronous code

71219.8k6](/packages/khr-php-mcurl-client)[pear/http_request2

Provides an easy way to perform HTTP requests.

764.2M48](/packages/pear-http-request2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
