PHPackages                             chillerlan/php-httpinterface - 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. chillerlan/php-httpinterface

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

chillerlan/php-httpinterface
============================

A PSR-7/17/18 http message/client implementation

6.0.0(2y ago)1417.1k—4.5%35MITPHPPHP ^8.1

Since Jan 23Pushed 2y ago2 watchersCompare

[ Source](https://github.com/chillerlan/php-httpinterface)[ Packagist](https://packagist.org/packages/chillerlan/php-httpinterface)[ Fund](https://ko-fi.com/codemasher)[ RSS](/packages/chillerlan-php-httpinterface/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (18)Used By (5)

chillerlan/php-httpinterface
============================

[](#chillerlanphp-httpinterface)

A [PSR-7](https://www.php-fig.org/psr/psr-7/)/[PSR-17](https://www.php-fig.org/psr/psr-17/)/[PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP message/client implementation.

[![PHP Version Support](https://camo.githubusercontent.com/ba60d3fc60045199e38d0f7e0560ccd1288be97b4548e611870cdc00e25fd0d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6368696c6c65726c616e2f7068702d68747470696e746572666163653f6c6f676f3d70687026636f6c6f723d383839324246)](https://www.php.net/supported-versions.php)[![version](https://camo.githubusercontent.com/06a5ea154f817b49d4b63b3919def22a5c5d853bf4fd4ec6bd509345c6de7085/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696c6c65726c616e2f7068702d68747470696e746572666163652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/chillerlan/php-httpinterface)[![license](https://camo.githubusercontent.com/f8cb649ee99a7fbca44bc4ca0ba36623c9e9b0837a96b1044c3197c24a896a5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6368696c6c65726c616e2f7068702d68747470696e746572666163652e737667)](https://github.com/chillerlan/php-httpinterface/blob/main/LICENSE)[![Continuous Integration](https://camo.githubusercontent.com/65ebb489a2c2df6c8ee455b9ebe94cd3cc940e2b1e35ca6746bde90c67d9e09c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6368696c6c65726c616e2f7068702d68747470696e746572666163652f63692e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562)](https://github.com/chillerlan/php-httpinterface/actions/workflows/ci.yml?query=branch%3Amain)[![Coverage](https://camo.githubusercontent.com/29474de70e9a2c853014941bd2b298917a142a02148541098ac9dd7dc19f5a0d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6368696c6c65726c616e2f7068702d68747470696e746572666163652e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/github/chillerlan/php-httpinterface)[![Codacy](https://camo.githubusercontent.com/8c5439c9014c41bc4dc6588216d07bcd857aea3f7f5ad1e4faa361afb25359f2/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f30616433613566396162653534376363613564356233646666306261333338333f6c6f676f3d636f64616379)](https://app.codacy.com/gh/chillerlan/php-httpinterface/dashboard)[![Packagist downloads](https://camo.githubusercontent.com/1fd9b570877f0caddd2b76abae249345081d5f616a1b0284c89bd59e9086f923/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696c6c65726c616e2f7068702d68747470696e746572666163652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/chillerlan/php-httpinterface/stats)

Documentation
=============

[](#documentation)

An API documentation created with [phpDocumentor](https://www.phpdoc.org/) can be found at  (WIP).

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

[](#requirements)

- PHP 8.1+
    - [`ext-curl`](https://www.php.net/manual/book.curl.php)
    - from dependencies:
        - [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php)
        - [`ext-intl`](https://www.php.net/manual/book.intl.php)
        - [`ext-json`](https://www.php.net/manual/book.json.php)
        - [`ext-mbstring`](https://www.php.net/manual/book.mbstring.php)
        - [`ext-simplexml`](https://www.php.net/manual/book.simplexml.php)
        - [`ext-zlib`](https://www.php.net/manual/book.zlib.php)

Installation with [composer](https://getcomposer.org)
-----------------------------------------------------

[](#installation-with-composer)

### Terminal

[](#terminal)

```
composer require chillerlan/php-httpinterface

```

### composer.json

[](#composerjson)

```
{
	"require": {
		"php": "^8.1",
		"chillerlan/php-httpinterface": "dev-main#"
	}
}
```

Note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^6.0` - see [releases](https://github.com/chillerlan/php-httpinterface/releases) for valid versions.

Profit!

Quickstart
----------

[](#quickstart)

The HTTP clients `CurlClient` and `StreamClient` are invoked with a `ResponseFactoryInterface` instance as the first parameter, followed by optional `HTTPOptions` and PSR-3 `LoggerInterface` instances. You can then send a request via the implemented PSR-18 method `ClientInterface::sendRequest()`, using a PSR-7 `RequestInterface` and expect a PSR-7 `ResponseInterface`.

### `CurlClient`, `StreamClient`

[](#curlclient-streamclient)

```
$options                 = new HTTPOptions;
$options->ca_info        = '/path/to/cacert.pem';
$options->user_agent     = 'my cool user agent 1.0';
$options->dns_over_https = 'https://cloudflare-dns.com/dns-query';

$httpClient = new CurlClient($responseFactory, $options, $logger);
$request    = $requestFactory->createRequest('GET', 'https://www.example.com?foo=bar');

$httpClient->sendRequest($request);
```

### `CurlMultiClient`

[](#curlmulticlient)

The `CurlMultiClient` client implements asynchronous multi requests (["rolling-curl"](https://code.google.com/archive/p/rolling-curl/)). It needs a `MultiResponseHandlerInterface` that parses the incoming responses, the callback may return a failed request to the stack:

```
$handler = new class () implements MultiResponseHandlerInterface{

	public function handleResponse(
		ResponseInterface $response,  // the incoming response
		RequestInterface  $request,   // the corresponding request
		int               $id,        // the request id
		array|null        $curl_info, // the curl_getinfo() result for this request
	):RequestInterface|null{

		if($response->getStatusCode() !== 200){
			// return the failed request back to the stack
			return $request;
		}

		try{
			$body = $response->getBody();

			// the response body is empty for some reason, we pretend that's fine and exit
			if($body->getSize() === 0){
				return null;
			}

			// parse the response body, store the result etc.
			$data = $body->getContents();

			// save data to file, database or whatever...
			// ...

		}
		catch(Throwable){
			// something went wrong, return the request to the stack for another try
			return $request;
		}

		// everything ok, nothing to return
		return null;
	}

};
```

You can then invoke the multi request client - the `MultiResponseHandlerInterface` and `ResponseFactoryInterface` are mandatory, `HTTPOptions` and `LoggerInterface` are optional:

```
$options              = new HTTPOptions;
$options->ca_info     = '/path/to/cacert.pem';
$options->user_agent  = 'my cool user agent 1.0';
$options->sleep       = 750000; // microseconds, see usleep()
$options->window_size = 5;
$options->retries     = 1;

$multiClient = new CurlMultiClient($handler, $responseFactory, $options, $logger);

// create and add the requests
foreach(['..', '...', '....'] as $item){
	$multiClient->addRequest($factory->createRequest('GET', $endpoint.'/'.$item));
}

// process the queue
$multiClient->process();
```

### `URLExtractor`

[](#urlextractor)

The `URLExtractor` wraps a PSR-18 `ClientInterface` to extract and follow shortened URLs to their original location.

```
$options                 = new HTTPOptions;
$options->user_agent     = 'my cool user agent 1.0';
$options->ssl_verifypeer = false;
$options->curl_options   = [
	CURLOPT_FOLLOWLOCATION => false,
	CURLOPT_MAXREDIRS      => 25,
];

$httpClient   = new CurlClient($responseFactory, $options, $logger);
$urlExtractor = new URLExtractor($httpClient, $responseFactory);

$request = $factory->createRequest('GET', 'https://t.co/ZSS6nVOcVp');

$urlExtractor->sendRequest($request); // -> response from the final location

// you can retrieve an array with all followed locations afterwards
$responses = $this->http->getResponses(); // -> ResponseInterface[]

// if you just want the URL of the final location, you can use the extract method:
$url = $this->http->extract('https://t.co/ZSS6nVOcVp'); // -> https://api.guildwars2.com/v2/build
```

### `LoggingClient`

[](#loggingclient)

The `LoggingClient` wraps a `ClientInterface` and outputs the HTTP messages in a readable way through a `LoggerInterface` (do NOT use in production!).

```
$loggingClient = new LoggingClient($httpClient, $logger);

$loggingClient->sendRequest($request); // -> log to output given via logger
```

### Auto generated API documentation

[](#auto-generated-api-documentation)

The API documentation can be auto generated with [phpDocumentor](https://www.phpdoc.org/). There is an [online version available](https://chillerlan.github.io/php-httpinterface/) via the [gh-pages branch](https://github.com/chillerlan/php-httpinterface/tree/gh-pages) that is [automatically deployed](https://github.com/chillerlan/php-httpinterface/deployments) on each push to main.

Locally created docs will appear in the directory `.build/phpdocs/`. If you'd like to create local docs, please follow these steps:

- [download phpDocumentor](https://github.com/phpDocumentor/phpDocumentor/releases) v3+ as .phar archive
- run it in the repository root directory:
    - on Windows `c:\path\to\php.exe c:\path\to\phpDocumentor.phar --config=phpdoc.xml`
    - on Linux just `php /path/to/phpDocumentor.phar --config=phpdoc.xml`
- open [index.html](./.build/phpdocs/index.html) in a browser
- profit!

Disclaimer
----------

[](#disclaimer)

Use at your own risk!

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

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

Recently: every ~421 days

Total

16

Last Release

794d ago

Major Versions

1.1.2 → 2.0.02018-08-08

2.0.0 → 3.0.02019-02-23

3.1.2 → 4.0.02019-11-10

4.0.0 → 5.0.02021-04-03

5.0.1 → 6.0.02024-03-15

PHP version history (5 changes)1.0.0PHP ^7.0.3

2.0.0PHP ^7.2.0

3.0.0PHP ^7.2

5.0.0PHP ^7.4 || ^8.0

6.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (485 commits)")

---

Tags

curlhttplet-php5-diephpphp-httpphp-http-clientphp5-is-deadphp7-is-deadphp8psr-17psr-18psr-7httpresponserequestpsr-7messageclientfactorypsr-17psr-18

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chillerlan-php-httpinterface/health.svg)

```
[![Health](https://phpackages.com/badges/chillerlan-php-httpinterface/health.svg)](https://phpackages.com/packages/chillerlan-php-httpinterface)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2243.9k1](/packages/vultr-vultr-php)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)

PHPackages © 2026

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