PHPackages                             undercloud/psr18 - 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. undercloud/psr18

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

undercloud/psr18
================

PSR-18 HTTP Client

226PHP

Since Mar 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/undercloud/psr18)[ Packagist](https://packagist.org/packages/undercloud/psr18)[ RSS](/packages/undercloud-psr18/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (2)Used By (0)

PSR-18 HTTP Client
==================

[](#psr-18-http-client)

[![Build Status](https://camo.githubusercontent.com/07d9653a4d28a11dc52af4a3ceedd4a50e059614d65a4ad75cc2b5b6f7ca13f4/68747470733a2f2f7472617669732d63692e6f72672f756e646572636c6f75642f70737231382e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/undercloud/psr18)

Implementation of

Features
--------

[](#features)

- PSR-18 compatible
- Supports of any type of HTTP requests
- JSON requests
- Body with multipart/form-data
- Upload / Download huge files
- SSL / TLS
- Proxy

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

[](#requirements)

PHP 7.1+

License
-------

[](#license)

MIT

Install
-------

[](#install)

`composer require undercloud/psr18`

Usage
-----

[](#usage)

```
$responsePrototype = new Zend\Diactoros\Response;

$httpClient = new Undercloud\Psr18\HttpClient($responsePrototype, [
    'timeout' => 10,
    'ssl' => [
        'verifyPeer' => false,
        'verifyPeerName' => false
    ]
]);

$requestPrototype = new Zend\Diactoros\Request('https://your-domain-name.com/post-data','POST');

$body = new Undercloud\Psr18\Streams\JsonStream([
    'foo' => 'bar'
]);
// or
$body = new Undercloud\Psr18\Streams\MultipartStream([
    'title' => 'Summer 69',
    'description' => 'Hey check it out...',
    'tags => ['summer','beach','sea'],
    'photo' => new Undercloud\Psr18\Streams\FileStream(
        $pathToFile
    )
]);

$requestPrototype = $requestPrototype->withBody($body);

$responsePrototype = $httpClient->sendRequest($requestPrototype);
```

Streams
-------

[](#streams)

### TextStream

[](#textstream)

```
// simple text stream
new Undercloud\Psr18\Streams\TextStream('PHP7 is Awesome')

// with options
$base64 = base64_encode('PHP7 is Awesome');

new Undercloud\Psr18\Streams\TextStream($base64, [
    'mime' => 'text/plain'
    'encoding' => 'base64'
])

// URL encode
$urlencode = urlencode('PHP7 is Awesome');

new Undercloud\Psr18\Streams\TextStream($urlencode);
```

### JsonStream

[](#jsonstream)

```

  JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES

$data = [
    'foo' => 'bar'
];

$jsonStream = new Undercloud\Psr18\Streams\JsonStream($data, $encodingOptions = 79)

// {"foo":"bar"}
$jsonStream->getContents();
```

### SocketStream

[](#socketstream)

```
// fopen
// stream_socket_client

new Undercloud\Psr18\Streams\SocketStream($resource);
```

### MultipartStream

[](#multipartstream)

```
new Undercloud\Psr18\Streams\MultipartStream([
    'simple' => 'text',
    'array' => ['foo','bar','baz'],
    'base64' => => new Undercloud\Psr18\Streams\TextStream(
        'iVBORw0KGgoAAAA...', [
            'mime' => 'image/png',
            'encoding' => 'base64'
        ]
    ),
    'json' => new Undercloud\Psr18\Streams\JsonStream([
        'foo' => 'bar
    ]),
    'photos' => [
        new Undercloud\Psr18\Streams\FileStream('/path/to/01.jpg'),
        new Undercloud\Psr18\Streams\FileStream('/path/to/02.jpg'),
        new Undercloud\Psr18\Streams\FileStream('/path/to/03.jpg'),
        ...
    ]
])
```

### FileStream

[](#filestream)

```
new Undercloud\Psr18\Streams\FileStream($path, $filename = '')
```

### WrapStream

[](#wrapstream)

```
// Third party stream

new Undercloud\Psr18\Streams\WrapStream(
    Psr\Http\Message\StreamInterface $stream
);
```

Extra Multipart Headers
-----------------------

[](#extra-multipart-headers)

All kind of streams:

- TextStream
- JsonStream
- SocketStream
- MultipartStream
- FileStream
- WrapStream

supports additional headers in multipart context

```
new Undercloud\Psr18\Streams\MultipartStream([
    'photo' => new Undercloud\Psr18\Streams\FileStream($path)
        ->withHeader('Content-Transfer-Encoding', '8bit')
])
```

Options
-------

[](#options)

- **timeout** *(boolean)*
    Number of seconds until the connect() system call should timeout. Defaults to 30.
- **followLocation** *(boolean)*
    Follow Location header redirects. Set to false to disable. Defaults to true.
- **maxRedirects** *(integer)*
    The max number of redirects to follow. Value 1 or less means that no redirects are followed. Defaults to 5.
- **waitResponse** *(boolean)*
    Defaults to TRUE.
- **requestFullUri** *(boolean)*
    When set to TRUE, the entire URI will be used when constructing the request. (i.e. GET  HTTP/1.0). While this is a non-standard request format, some proxy servers require it. Defaults to FALSE.
- **proxy** *(string)*
    URI specifying address of proxy server. (e.g. tcp://proxy.example.com:5100).
- **sslProtocol** *(string)*
    One of `ssl`, `tls`, `tlsv1.0`, `tlsv1.1`, `tlsv1.2`Defaults to max TLS version defined in **stream\_get\_transports**
- **ssl** *(array)*
    SSL context options

### SSL Context Options

[](#ssl-context-options)

- **peerName** *(string)*
    Peer name to be used. If this value is not set, then the name is guessed based on the hostname used when opening the stream.
- **verifyPeer** *(boolean)*
    Require verification of SSL certificate used.
    Defaults to TRUE.
- **verifyPeerName** *(boolean)*
    Require verification of peer name.
    Defaults to TRUE.
- **allowSelfSigned** *(boolean)*
    Allow self-signed certificates. Requires **verifyPeer**.
    Defaults to FALSE
- **cafile** *(string)*Location of Certificate Authority file on local filesystem which should be used with the **verifyPeer** context option to authenticate the identity of the remote peer.
- **capath** *(string)*
    If cafile is not specified or if the certificate is not found there, the directory pointed to by capath is searched for a suitable certificate. capath must be a correctly hashed certificate directory.
- **localCert** *(string)*
    Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. It can optionally contain the certificate chain of issuers. The private key also may be contained in a separate file specified by **localPk**.
- **localPk** *(string)*
    Path to local private key file on filesystem in case of separate files for certificate (**localCert**) and private key.
- **passphrase** *(string)*
    Passphrase with which your **localCert** file was encoded.
- **CNMatch** *(string)*
    Common Name we are expecting. PHP will perform limited wildcard matching. If the Common Name does not match this, the connection attempt will fail.
    Note: This option is deprecated, in favour of **peerName**, as of PHP 5.6.0.
- **verifyDepth** *(integer)*
    Abort if the certificate chain is too deep.
    Defaults to no verification.
- **ciphers** *(string)*
    Sets the list of available ciphers. The format of the string is described in . Defaults to DEFAULT.
- **capturePeerCert** *(boolean)*
    If set to TRUE a peer\_certificate context option will be created containing the peer certificate.
- **capturePeerCertChain** *(boolean)*
    If set to TRUE a **peerCertificateChain** context option will be created containing the certificate chain.
- **SNIEnabled** *(boolean)*If set to TRUE server name indication will be enabled. Enabling SNI allows multiple certificates on the same IP address.
- **SNIServerName** *(string)*
    If set, then this value will be used as server name for server name indication. If this value is not set, then the server name is guessed based on the hostname used when opening the stream.
    Note: This option is deprecated, in favour of **peerName**, as of PHP 5.6.0.
- **disableCompression** *(boolean)*
    If set, disable TLS compression. This can help mitigate the CRIME attack vector.
- **peerFingerprint** *(string | array)*
    Aborts when the remote certificate digest doesn't match the specified hash. When a string is used, the length will determine which hashing algorithm is applied, either "md5" (32) or "sha1" (40). When an array is used, the keys indicate the hashing algorithm name and each corresponding value is the expected digest.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/920a45a1bd1af5960cf6781cd2d8831ebfe2890c1077210667802afa109d8d13?d=identicon)[undercloud](/maintainers/undercloud)

---

Top Contributors

[![undercloud](https://avatars.githubusercontent.com/u/9054259?v=4)](https://github.com/undercloud "undercloud (37 commits)")

---

Tags

http-clientphpphp-figphp7psr-7psr18

### Embed Badge

![Health badge](/badges/undercloud-psr18/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M81](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.8k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M89](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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