PHPackages                             hightman/httpclient - 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. hightman/httpclient

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

hightman/httpclient
===================

A parallel HTTP client written in pure PHP

v1.13(4y ago)1075.9k↓100%22[1 issues](https://github.com/hightman/httpclient/issues)MITPHPPHP &gt;=5.4.0

Since Sep 10Pushed 4y ago10 watchersCompare

[ Source](https://github.com/hightman/httpclient)[ Packagist](https://packagist.org/packages/hightman/httpclient)[ Docs](http://hightman.cn/)[ RSS](/packages/hightman-httpclient/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (15)Used By (0)

A parallel HTTP client written in pure PHP
==========================================

[](#a-parallel-http-client-written-in-pure-php)

This is a powerful HTTP client written in pure PHP code, dose not require any other PHP extension. It help you easy to send HTTP request and handle its response.

- Process multiple requests in parallel
- Full support for HTTP methods, including GET, POST, HEAD, ...
- Customizable HTTP headers, full support for Cookie, X-Server-Ip
- Follows 301/302 redirect, can set the maximum times
- Supports Keep-Alive, reuse connection to the same host
- Supports HTTPS with openssl
- Allow to upload file via POST method
- Detailed information in DEBUG mode
- Free and open source, release under MIT license

Requirements
------------

[](#requirements)

PHP &gt;= 5.4.0

Install
-------

[](#install)

### Install from an Archive File

[](#install-from-an-archive-file)

Extract the archive file downloaded from [httpclient-master.zip](https://github.com/hightman/httpclient/archive/master.zip)to your project. And then add the library file into your program:

```
require '/path/to/httpclient.inc.php';
```

### Install via Composer

[](#install-via-composer)

If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).

You can then install this library using the following command:

```
php composer.phar require "hightman/httpclient:*"

```

Usage
-----

[](#usage)

### Quick to use

[](#quick-to-use)

We have defined some shortcut methods, they can be used as following:

```
use hightman\http\Client;

$http = new Client();

// 1. display response contents
echo $http->get('http://www.baidu.com');
echo $http->get('http://www.baidu.com/s', ['wd' => 'php']);

// 2. capture the response object, read the meta information
$res = $http->get('http://www.baidu.com');
print_r($res->getHeader('content-type'));
print_r($res->getCookie(null));

// 3. post request
$res = $http->post('http://www.your.host/', ['field1' => 'value1', 'field2' => 'value2']);
if (!$res->hasError()) {
   echo $res->body;    // response content
   echo $res->status;  // response status code
}

// 4. head request
$res = $http->head('http://www.baidu.com');
print_r($res->getHeader(null));

// delete request
$res = $http->delete('http://www.your.host/request/uri');

// 5. restful json requests
// there are sismilar api like: postJson, putJson
$data = $http->getJson('http://www.your.host/request/uri');
print_r($data);

$data = $http->postJson('http://www.your.host/reqeust/uri', ['key1' => 'value1', 'key2' => 'value2']);
```

### Customize request

[](#customize-request)

You can also customize various requests by passing in `Request` object.

```
use hightman\http\Client;
use hightman\http\Request;

$http = new Client();
$request = new Request('http://www.your.host/request/uri');

// set method
$request->setMethod('POST');
// add headers
$request->setHeader('user-agent', 'test robot');

// specify host ip, this will skip DNS resolver
$request->setHeader('x-server-ip', '1.2.3.4');

// add post fields
$request->addPostField('name', 'value');
$request->addPostFile('upload', '/path/to/file');
$request->addPostFile('upload_virtual', 'virtual.text', 'content of file ...');

// or you can specify request body directly
$request->setBody('request body ...');

// you also can specify JSON data as request body
// this will set content-type header to 'application/json' automatically.
$request->setJsonBody(['key' => 'value']);

// specify context options of connect, such as SSL options
$request->contextOptions = [
    'ssl' => ['verify_peer_name' => false, 'local_cert' => '/path/to/file.pem'],
];

// execute the request
$response = $http->exec($request);
print_r($response);
```

### Multiple get in parallel

[](#multiple-get-in-parallel)

A great features of this library is that we can execute multiple requests in parallel. For example, executed three requests simultaneously, the total time spent is one of the longest, rather than their sum.

```
use hightman\http\Client;
use hightman\http\Request;
use hightman\http\Response;

// Define callback as function, its signature:
// (callback) (Response $res, Request $req, string|integer $key);
function test_cb($res, $req, $key)
{
   echo '[' . $key . '] url: ' . $req->getUrl() . ', ';
   echo 'time cost: ' . $res->timeCost . ', size: ' . number_format(strlen($res->body)) . "\n";
}

// or you can define callback as a class implemented interface `ParseInterface`.
class testCb implements \hightman\http\ParseInterface
{
  public function parse(Response $res, Request $req, $key)
  {
    // your code here ...
  }
}

// create client object with callback parser
$http = new \hightman\http\Client('test_cb');

// or specify later as following
$http->setParser(new testCb);

// Fetch multiple URLs, it returns after all requests are finished.
// It may be slower for the first time, because of DNS resolover.
$results = $http->mget([
  'baidu' => 'http://www.baidu.com/',
  'sina' => 'http://news.sina.com.cn/',
  'qq' => 'http://www.qq.com/',
]);

// show all results
// print_r($results);
```

> Note: There are other methods like: mhead, mpost, mput ... If you need handle multiple different requests, you can pass an array of `Request`objects into `Client::exec($reqs)`.

### Export and reused cookies

[](#export-and-reused-cookies)

This library can intelligently manage cookies, default store cookies in memory and send them on need. We can export all cookies after `Client` object destoried.

```
$http->setCookiePath('/path/to/file');
```

### Add bearer authorization token

[](#add-bearer-authorization-token)

```
$http->setHeader('authorization', 'Bearer ' . $token);
// or add header for request object
$request->setHeader('authorization', 'Bearer ' . $token);
```

### Use proxy

[](#use-proxy)

```
// use socks5
Connection::useProxy('socks5://127.0.0.1:1080');
// use socks5 with username & password
Connection::useProxy('socks5://user:pass@127.0.0.1:1080');
// use HTTP proxy
Connection::useProxy('http://127.0.0.1:8080');
// use HTTP proxy with basic authentication
Connection::useProxy('http://user:pass@127.0.0.1:8080');
// use socks4 proxy
Connection::useProxy('socks4://127.0.0.1:1080');
// disable socks
Connection::useProxy(null);
```

### Enable debug mode

[](#enable-debug-mode)

You can turn on debug mode via `Client::debug('open')`. This will display many debug messages to help you find out problem.

### Others

[](#others)

Because of `Client` class also `use HeaderTrait`, you can use `Client::setHeader()`to specify global HTTP headers for requests handled by this client object.

Contact me
----------

[](#contact-me)

If you have any questions, please report on github [issues](https://github.com/hightman/httpclient/issues)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

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 ~170 days

Recently: every ~1 days

Total

14

Last Release

1684d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/720b188c6d958d43fbf848b3211a7a8419cc4ef9e116913763835782d4dd134d?d=identicon)[hightman](/maintainers/hightman)

---

Top Contributors

[![hightman](https://avatars.githubusercontent.com/u/812381?v=4)](https://github.com/hightman "hightman (26 commits)")

---

Tags

phprestcurlhttp client

### Embed Badge

![Health badge](/badges/hightman-httpclient/health.svg)

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

###  Alternatives

[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[eightpoints/guzzle-bundle

Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony. Comes with easy and powerful configuration options and optional plugins.

45912.1M55](/packages/eightpoints-guzzle-bundle)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)[popphp/pop-http

Pop Http Component for Pop PHP Framework

1018.5k13](/packages/popphp-pop-http)

PHPackages © 2026

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