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

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

mediawiki/http-request
======================

A minimalistic http/curl request interface library

2.0.0(3y ago)0180.2k↑30%2GPL-2.0-or-laterPHPPHP &gt;=8.0CI passing

Since Jul 22Pushed 1y ago12 watchersCompare

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

READMEChangelogDependencies (2)Versions (8)Used By (2)

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

[](#http-request)

[![GitHub Workflow Status](https://camo.githubusercontent.com/dfa9219fb84faed184f274b10994a4d136777bfb4fc7080808f246590c19a727/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f53656d616e7469634d6564696157696b692f687474702d726571756573742f63692e796d6c3f6272616e63683d6d6173746572)](https://github.com/SemanticMediaWiki/http-request/actions?query=workflow%3ACI)[![Latest Stable Version](https://camo.githubusercontent.com/4072db99e438e7242385c2f860bde9613cf1d1985ce3d80fbfa1ab01e980776e/68747470733a2f2f706f7365722e707567782e6f72672f6d6564696177696b692f687474702d726571756573742f76657273696f6e2e706e67)](https://packagist.org/packages/mediawiki/http-request)[![Packagist download count](https://camo.githubusercontent.com/003b1ca2b46a2fae4c4ddd777a8132fc974712e3f0e3db1b6c69405f4c386a01/68747470733a2f2f706f7365722e707567782e6f72672f6d6564696177696b692f687474702d726571756573742f642f746f74616c2e706e67)](https://packagist.org/packages/mediawiki/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 8.0 or later

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

[](#installation)

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

```
{
	"require": {
		"mediawiki/http-request": "~2.0"
	}
}
```

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 you can:

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

A list of people who have made contributions in the past can be found [here](https://github.com/SemanticMediaWiki/http-request/graphs/contributors).

### Tests

[](#tests)

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

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

[](#release-notes)

### 2.0.0 (2022-12-13)

[](#200-2022-12-13)

- Increased minimum PHP requirement to 8.0

### 1.3.1 (2017-01-14)

[](#131-2017-01-14)

- Extended `SocketRequest` to match a possible TLS port

### 1.3.0 (2015-11-23)

[](#130-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)

[](#120-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)

[](#110-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)

[](#100-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

44

—

FairBetter than 92% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 56.3% 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 ~450 days

Recently: every ~650 days

Total

7

Last Release

1252d ago

Major Versions

1.3.1 → 2.0.02022-12-13

PHP version history (2 changes)1.0.0PHP &gt;=5.3.2

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://avatars.githubusercontent.com/u/22235?v=4)[Stefan Wasilewski](/maintainers/SMW)[@smw](https://github.com/smw)

![](https://avatars.githubusercontent.com/u/1104078?v=4)[Karsten Hoffmeyer](/maintainers/kghbln)[@kghbln](https://github.com/kghbln)

![](https://www.gravatar.com/avatar/5d30e82252731745d5060a641de6e9431e1d5722ede97cb1cc94d2975aa54753?d=identicon)[malberts](/maintainers/malberts)

---

Top Contributors

[![mwjames](https://avatars.githubusercontent.com/u/1245473?v=4)](https://github.com/mwjames "mwjames (27 commits)")[![malberts](https://avatars.githubusercontent.com/u/1428594?v=4)](https://github.com/malberts "malberts (11 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (6 commits)")[![kghbln](https://avatars.githubusercontent.com/u/1104078?v=4)](https://github.com/kghbln "kghbln (2 commits)")[![jaideraf](https://avatars.githubusercontent.com/u/3636594?v=4)](https://github.com/jaideraf "jaideraf (1 commits)")[![paladox](https://avatars.githubusercontent.com/u/5727000?v=4)](https://github.com/paladox "paladox (1 commits)")

---

Tags

curlhttp request

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/mediawiki-http-request/health.svg)](https://phpackages.com/packages/mediawiki-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)
