PHPackages                             onoi/http-request - 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. onoi/http-request

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

onoi/http-request
=================

A minimalistic http/curl request interface library

1.3.1(9y ago)3327.6k↑100%2[1 PRs](https://github.com/onoi/http-request/pulls)3GPL-2.0+PHPPHP &gt;=5.3.2

Since Jul 22Pushed 3y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (7)Used By (3)

Http request
============

[](#http-request)

[![Build Status](https://camo.githubusercontent.com/9378892400c91c3b5714ed8bcafab0e5925d0012c55802bfe8c3749012b9b1b5/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f6e6f692f687474702d726571756573742e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/onoi/http-request)[![Code Coverage](https://camo.githubusercontent.com/a274769ff43e963f9b7f694b994bb1a06c6b62f76652658b3eb4b628f746fba7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f687474702d726571756573742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/http-request/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/afa6687ce0d7dc97f8e1d5f08dd57db8d49b7b7bd224109c205e73a7c7eb9766/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6e6f692f687474702d726571756573742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/onoi/http-request/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/8858d89f8d668d11a12a2d751805dbf39f2fae0d4fd85448ec3db93d79d8b0f4/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f687474702d726571756573742f76657273696f6e2e706e67)](https://packagist.org/packages/onoi/http-request)[![Packagist download count](https://camo.githubusercontent.com/ea082a47741409f37691eb72536a49de56b1a7c3ec196e259058f3f94c5df8f2/68747470733a2f2f706f7365722e707567782e6f72672f6f6e6f692f687474702d726571756573742f642f746f74616c2e706e67)](https://packagist.org/packages/onoi/http-request)[![Dependency Status](https://camo.githubusercontent.com/8424058fae2eb1a1dab7d330960c74d3f5e066036162c46a4d8311461a359fae/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f6f6e6f693a687474702d726571756573742f62616467652e706e67)](https://www.versioneye.com/php/onoi:http-request)

A minimalistic http/curl request interface that was part of the [Semantic MediaWiki](https://github.com/SemanticMediaWiki/SemanticMediaWiki/) code base and is now being deployed as independent library.

This library provides:

- `HttpRequest` interface
- `CurlRequest` as cURL implementation of the `HttpRequest`
- `CachedCurlRequest` to support low-level caching on repeated `CurlRequest` requests
- `MultiCurlRequest` to make use of the cURL multi stack feature
- `SocketRequest` to create asynchronous socket connections

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

[](#requirements)

- PHP 5.3 or later

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

[](#installation)

The recommended installation method for this library is by adding the dependency to your [composer.json](https://getcomposer.org/).

```
{
	"require": {
		"onoi/http-request": "~1.3"
	}
}
```

Usage
-----

[](#usage)

```
use Onoi\HttpRequest\CurlRequest;
use Onoi\HttpRequest\Exception\BadHttpResponseException;
use Onoi\HttpRequest\Exception\HttpConnectionException;

class Foo {

	private $curlRequest = null;

	public function __constructor( CurlRequest $curlRequest ) {
		$this->curlRequest = $curlRequest;
	}

	public function doMakeHttpRequestTo( $url ) {

		$this->curlRequest->setOption( CURLOPT_URL, $url );

		if ( !$this->curlRequest->ping() ) {
			throw new HttpConnectionException( "Couldn't connect" );
		}

		$this->curlRequest->setOption( CURLOPT_RETURNTRANSFER, true );

		$this->curlRequest->setOption( CURLOPT_HTTPHEADER, array(
			'Accept: application/x-turtle'
		) );

		$response = $this->curlRequest->execute();

		if ( $this->curlRequest->getLastErrorCode() == 0 ) {
			return $response;
		}

		throw new BadHttpResponseException( $this->curlRequest );
	}
}
```

```
$httpRequestFactory = new HttpRequestFactory();

$instance = new Foo( $httpRequestFactory->newCurlRequest() );
$response = $instance->doMakeHttpRequestTo( 'http://example.org' );

OR

$cacheFactory = new CacheFactory();

$compositeCache = $cacheFactory->newCompositeCache( array(
	$cacheFactory->newFixedInMemoryLruCache( 500 ),
	$cacheFactory->newDoctrineCache( new \Doctrine\Common\Cache\RedisCache() )
) );

$httpRequestFactory = new HttpRequestFactory( $compositeCache );
$cachedCurlRequest = $httpRequestFactory->newCachedCurlRequest();

// Responses for a request with the same signature (== same endpoint and same query
// content) will be cached if the request was successful for a specified 1 h (3600 sec)
$cachedCurlRequest->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 60 * 60 );

$instance = new Foo( $cachedCurlRequest );
$response = $instance->doMakeHttpRequestTo( 'http://example.org' );
```

Contribution and support
------------------------

[](#contribution-and-support)

If you want to contribute work to the project please subscribe to the developers mailing list and have a look at the [contribution guidelinee](/CONTRIBUTING.md). A list of people who have made contributions in the past can be found [here](https://github.com/onoi/http-request/graphs/contributors).

- [File an issue](https://github.com/onoi/http-request/issues)
- [Submit a pull request](https://github.com/onoi/http-request/pulls)

### Tests

[](#tests)

The library provides unit tests that covers the core-functionality normally run by the [continues integration platform](https://travis-ci.org/onoi/http-request). Tests can also be executed manually using the PHPUnit configuration file found in the root directory.

Release notes
-------------

[](#release-notes)

- 1.3.1 (2016-01-14)

- Extended `SocketRequest` to match a possible TLS port

- 1.3.0 (2015-11-23)

- Deprecated `CachedCurlRequest::setCachePrefix` and `CachedCurlRequest::setExpiryInSeconds` in favor of setting it via the option `ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX` and `ONOI_HTTP_REQUEST_RESPONSECACHE_TTL` (any change in the expiry will auto-invalidate existing items in cache)
- Deprecated `CachedCurlRequest::isCached` in favor of `CachedCurlRequest::isFromCache`

- 1.2.0 (2015-11-09)

- Added "wasAccepted" to the `SocketRequest` response output
- Added option `ONOI_HTTP_REQUEST_FOLLOWLOCATION` to support resetting the URL location in case of a `301` HTTP response during a `SocketRequest::ping` request

- 1.1.0 (2015-09-12)

- Renamed `AsyncCurlRequest` to `MultiCurlRequest`
- Deprecated `MultiCurlRequest::setCallback` and to be replaced by `MultiCurlRequest::setOption( ONOI_HTTP_REQUEST_ON_COMPLETED_CALLBACK, ... )`
- Added `SocketRequest` to create asynchronous socket connections

- 1.0.0 (2015-07-22, initial release)

- Added the `HttpRequest` interface
- Added the `CurlRequest` implementation
- Added the `CachedCurlRequest` to extend the `CurlRequest` implementation
- Added the `AsyncCurlRequest` implementation

License
-------

[](#license)

[GNU General Public License 2.0 or later](https://www.gnu.org/copyleft/gpl.html).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 84.4% 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 ~108 days

Recently: every ~122 days

Total

6

Last Release

3411d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/372f9bc1233d5518b9522cb681210a8de2765a3a9bbde20138f6ad5332a411ca?d=identicon)[mwjames](/maintainers/mwjames)

![](https://www.gravatar.com/avatar/511b3dbc1a73ad7b69118e540b16c8bcc2ac5f923022b94aa61a8d71af612f9c?d=identicon)[onoi](/maintainers/onoi)

---

Top Contributors

[![mwjames](https://avatars.githubusercontent.com/u/1245473?v=4)](https://github.com/mwjames "mwjames (27 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (4 commits)")[![kghbln](https://avatars.githubusercontent.com/u/1104078?v=4)](https://github.com/kghbln "kghbln (1 commits)")

---

Tags

curlhttp request

### Embed Badge

![Health badge](/badges/onoi-http-request/health.svg)

```
[![Health](https://phpackages.com/badges/onoi-http-request/health.svg)](https://phpackages.com/packages/onoi-http-request)
```

###  Alternatives

[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M258](/packages/rmccue-requests)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[popphp/pop-http

Pop Http Component for Pop PHP Framework

1018.5k13](/packages/popphp-pop-http)[msankhala/parsehub-php

Php wrapper classes for Parsehub REST api.

1312.4k](/packages/msankhala-parsehub-php)

PHPackages © 2026

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