PHPackages                             sngrl/mcurl - 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. sngrl/mcurl

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

sngrl/mcurl
===========

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

3.1.0(9y ago)063MITPHPPHP &gt;=5.3.0

Since Jun 13Pushed 3y agoCompare

[ Source](https://github.com/sngrl/mcurl)[ Packagist](https://packagist.org/packages/sngrl/mcurl)[ Docs](http://github.com/khristenkoyura/mcurl)[ RSS](/packages/sngrl-mcurl/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (10)Used By (0)

MCurl - simple, but functional wrapper for curl
===============================================

[](#mcurl---simple-but-functional-wrapper-for-curl)

[![Build](https://camo.githubusercontent.com/e6827283388e9bb8dcb8a5daf132422f7a04f8cc2d56a115853c07c6a1d5ea48/68747470733a2f2f7472617669732d63692e6f72672f4b6872697374656e6b6f597572612f6d6375726c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/KhristenkoYura/mcurl)[![Version](https://camo.githubusercontent.com/96695961d4c7f1b3cee5b4e3b8a77c0fa2fab656e03fb12d6528dbaa34538954/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68722f7068702d6d6375726c2d636c69656e742e737667)](https://packagist.org/packages/khr/php-mcurl-client)[![License](https://camo.githubusercontent.com/ebad95c384c5f417456847629b7e43a2d3deaeef0e937571d5b94f8743010253/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68722f7068702d6d6375726c2d636c69656e742e737667)](https://github.com/KhristenkoYura/mcurl/blob/master/LICENSE)[![Downloads](https://camo.githubusercontent.com/16ab513bdeff7c24a7c4b131c3ca3dc55f4feafae1fdb246811e8e2524b16856/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b68722f7068702d6d6375726c2d636c69656e742e737667)](https://packagist.org/packages/khr/php-mcurl-client)

### Features:

[](#features)

- PHP &gt;= 5.3 (compatible up to version 7.0 &amp;&amp; hhvm)
- **stable**. Using many projects
- **fast** request. Minimal overhead
- run a query in a single line
- parallel request (Multi request). Default enable parallel request
- use async request
- **balancing requests**
- no callable

Install
-------

[](#install)

The recommended way to install multi curl is through [composer](http://getcomposer.org).

```
$ composer require khr/php-mcurl-client:3.*

```

```
{
    "require": {
        "khr/php-mcurl-client": "~3.0"
    }
}
```

Quick Start and Examples
========================

[](#quick-start-and-examples)

### Create

[](#create)

```
use MCurl\Client;
$client = new Client();
```

### Simple request

[](#simple-request)

```
echo $client->get('http://example.com');
```

### Check error

[](#check-error)

```
$result = $client->get('http://example.com');
echo (!$result->hasError()
    ? 'Ok: ' . $result
    : 'Error: ' .$result->error . ' ('.$result->errorCode.')')
    , PHP_EOL;
```

### Add curl options in request

[](#add-curl-options-in-request)

```
echo $client->get('http://example.com', [CURLOPT_REFERER => 'http://example.net/']);
```

### Post request

[](#post-request)

```
echo $client->post('http://example.com', ['post-key' => 'post-value'], [CURLOPT_REFERER => 'http://example.net/']);
```

### Simple parallel request

[](#simple-parallel-request)

```
// @var $results Result[]
$results = $client->get(['http://example.com', 'http://example.net']);
foreach($results as $result) {
    echo $result;
}
```

### Parallel request

[](#parallel-request)

```
$urls = ['http://example.com', 'http://example.net', 'http://example.org'];
foreach($urls as $url) {
    $client->add([CURLOPT_URL => $url]);
}
// wait all request
// @var $results Result[]
$results = $client->all();
```

### Parallel request; waiting only next result

[](#parallel-request-waiting-only-next-result)

```
$urls = ['http://example.com', 'http://example.net', 'http://example.org'];
foreach($urls as $url) {
    $client->add([CURLOPT_URL => $url]);
}
while($result = $client->next()) {
    echo $result;
}
```

### Dynamic add request

[](#dynamic-add-request)

```
while($result = $client->next()) {
    $urls = fun_get_urls_for_parse_result($result);
    foreach($urls as $url) {
        $client->add([CURLOPT_URL => $url]);
    }
    echo $result;
}
```

### Non-blocking request; use async code; only run request and check done

[](#non-blocking-request-use-async-code-only-run-request-and-check-done)

```
while($client->run() || $client->has()) {
    while($client->has()) {
        // no blocking
        $result = $client->next();
        echo $result;
    }

    // more async code

    //end more async code
}
```

### Use params

[](#use-params)

```
$result = $client->add([CURLOPT_URL => $url], ['id' => 7])->next();
echo $result->params['id']; // echo 7
```

### Result

[](#result)

```
// @var $result Result
$result->body; // string: body result
$result->json; // object; @see json_encode
$result->getJson(true); // array; @see json_encode
$result->headers['content-type']; // use $client->enableHeaders();
$result->info; // @see curl_getinfo();
$result->info['total_time']; // 0.001

$result->hasError(); // not empty curl_error or http code >=400
$result->hasError('network'); // only not empty curl_error
$result->hasError('http'); // only http code >=400
$result->getError(); // return message error, if ->hasError();
$result->httpCode; // return 200
```

### Config

[](#config)

#### Client::setOptions

[](#clientsetoptions)

This curl options add in all request

```
$client->setOptions([CURLOPT_REFERER => 'http://example.net/']);
```

#### Client::enableHeaders

[](#clientenableheaders)

Add headers in result

```
$client->enableHeaders();
```

#### Client::setMaxRequest

[](#clientsetmaxrequest)

The maximum number of queries executed in parallel

```
$client->setMaxRequest(20); // set 20 parallel request
```

#### Client::setSleep

[](#clientsetsleep)

To balance the requests in the time interval using the method **$client-&gt;setSleep**. It will help you to avoid stress (on the sending server) for receiving dynamic content by adjusting the conversion rate in the interval. Example:

```
$client->setSleep (20, 1);
```

1 second will run no more than 20 queries.

For static content is recommended restrictions on download speeds, that would not score channel. Example:

```
//channel 10 Mb.
$client->setMaxRequest (123);
$client->setOptions([CURLOPT_MAX_RECV_SPEED_LARGE => (10 * 1024 ^ 3) / 123]);
```

### Cookbook

[](#cookbook)

#### Download file

[](#download-file)

```
$client->get('http://exmaple.com/image.jpg', [CURLOPT_FILE => fopen('/tmp/image.jpg', 'w')]);
```

#### Save memory

[](#save-memory)

To reduce memory usage, you can write the query result in a temporary file.

```
$client->setStreamResult(Client::STREAM_FILE); // All Result write in tmp file.
```

```
/**
 * @see tests/ and source
 */
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 63.2% 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 ~103 days

Recently: every ~114 days

Total

8

Last Release

3629d ago

Major Versions

1.0 → 2.0.12015-03-06

2.0.3 → 3.0.12015-03-12

### Community

Maintainers

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

---

Top Contributors

[![KhristenkoYura](https://avatars.githubusercontent.com/u/570035?v=4)](https://github.com/KhristenkoYura "KhristenkoYura (55 commits)")[![sngrl](https://avatars.githubusercontent.com/u/6196684?v=4)](https://github.com/sngrl "sngrl (32 commits)")

---

Tags

httpphpasyncclientcurlparallelmultispiderrequests

### Embed Badge

![Health badge](/badges/sngrl-mcurl/health.svg)

```
[![Health](https://phpackages.com/badges/sngrl-mcurl/health.svg)](https://phpackages.com/packages/sngrl-mcurl)
```

###  Alternatives

[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)[swlib/saber

Swoole coroutine HTTP client

985145.0k27](/packages/swlib-saber)[smi2/phpclickhouse

PHP ClickHouse Client

83510.1M71](/packages/smi2-phpclickhouse)[chuyskywalker/rolling-curl

Rolling-Curl: A non-blocking, non-dos multi-curl library for PHP

207446.6k6](/packages/chuyskywalker-rolling-curl)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)

PHPackages © 2026

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