PHPackages                             ppajer/php-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. ppajer/php-request

Abandoned → [ppajer/request](/?search=ppajer%2Frequest)Library[HTTP &amp; Networking](/categories/http)

ppajer/php-request
==================

Intuitive and fluent wrappers for making cURL and multi-cURL requests.

010PHP

Since Jul 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ppajer/PHP-Request)[ Packagist](https://packagist.org/packages/ppajer/php-request)[ RSS](/packages/ppajer-php-request/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-Request
===========

[](#php-request)

Intuitive and fluent wrappers for making cURL and multi-cURL requests.

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

[](#installation)

To start using this library, you have two options: add it to your project's dependencies and use `composer install`, or download it manually and include either the `autoload.php` file or the class files directly.

Usage
-----

[](#usage)

### Single requests - `Request`

[](#single-requests---request)

The `Request` class represents a single request to a resource, and its settings. It provides a simple fluent API to create and edit requests, and some built-in constants for widespread options to save you the time of having to look up User Agent strings and content types for the most common uses. Additional convenience constants will be added over time.

#### Properties

[](#properties)

```
class Request {

	const UA_MOZILLA;
	const UA_CHROME;
	const UA_SAFARI;
	const UA_EXPLORER;
	const UA_EDGE;
	const UA_OPERA;

	const CONTENT_TYPE_XML;
	const CONTENT_TYPE_XHTML;
	const CONTENT_TYPE_TXT;
	const CONTENT_TYPE_TTF;
	const CONTENT_TYPE_MJS;
	const CONTENT_TYPE_JSONLD;
	const CONTENT_TYPE_JSON;
	const CONTENT_TYPE_JS;
	const CONTENT_TYPE_CSV;
	const CONTENT_TYPE_CSS;

	public $URL; // Default: null
	public $UA; // Default: UA_SAFARI
	public $method; // Default: "GET"
	public $content; // Default: null
	public $headers; // Default: null
	public $contentType; // Default: CONTENT_TYPE_TXT
	public $follow; // Default: true
}

```

#### Methods

[](#methods)

All methods except `response` return their instance of `Request` to allow method chaining.

```
class Request {

	public function __construct(String $url);

	public function URL(String $url) : Request // Sets the URL of the request.

	public function userAgent(String $UA) : Request // Sets the userAgent of the request.

	public function method(String $method) : Request // Sets the method of the request.

	public function content(Array $content) : Request // Sets the content of the request.

	public function headers(Array $headers) : Request // Sets the headers of the request.

	public function contentType(String $contentType) : Request // Sets the contentType of the request.

	public function follow(Bool $follow) : Request // Sets if the request should follow redirects.

	public function send() : Request // Processes the request.

	public function response() : String // Fetches the response body.

	public static function parallel(Array $options) : ParallelRequest // Creates an instance of ParallelRequest to handle multiple URLs. See the docs for ParallelRequest
}

```

### Multiple requests - `ParallelRequest`

[](#multiple-requests---parallelrequest)

The `ParallelRequest` class allows you to fetch a number of resources asynchronously, providing a large performance boost over making sequential requests. You can either create one directly using the `new` keyword or by calling `Request::parallel()` statically.

#### Methods

[](#methods-1)

Most of the API is the same as for a regular request, except for the constructor taking an array of request options. The array must consist of keys matching the parameters of the class - if provided, these keys will be used as settings for the individual requests, with the missing values being filled with class defaults. See [ParallelRequest constructor options](#constructor-request-options-example) for more details.

```
class ParallelRequest {

	public function __construct(Array $requestList);

	public function awaitAll() : ParallelRequest // Process all requests and wait for them to finish

	public function response() : Array // Gets the results of the batch. Each response is found under the same key in the resulting array as the one used to mark its request in the request options array passed to the constructor. Example below.
}

```

##### Constructor request options example

[](#constructor-request-options-example)

```
$opts = [
	'someKey' => [
		'URL' => 'https://...',
		'method' => 'POST',
		'content' => [
			'foo' => 'bar'
		]
	],
	'someOtherKey' => [
		'URL' => 'https://...'
	]
];

/*

Will return:
[
	'someKey' => ' '...' // Response from the URL with default GET
]

*/

```

Full example
------------

[](#full-example)

```

require 'php-request/autoload.php';

// Single
$url = 'http://some.api.com';

$singleRequest = new Request($url);
$singleRequest->userAgent(Request::UA_CHROME)
			->contentType(Request::CONTENT_TYPE_JSON)
			->content(json_encode($someData))
			->method('POST')
			->send();

$response = $singleRequest->response();

// Multiple
$opts = [
	'A' => [
		'URL' => '...'
	],
	'B' => [
		'URL' => '...'
	],
	...
];

$parallel = new ParallelRequest($opts);
$response = $parallel->awaitAll()->response();

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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/1e6212007de7bf9a8e3591e60269ffaf607a962926182e21646b8f9975a879e4?d=identicon)[ppajer](/maintainers/ppajer)

---

Top Contributors

[![ppajer](https://avatars.githubusercontent.com/u/5861559?v=4)](https://github.com/ppajer "ppajer (8 commits)")

### Embed Badge

![Health badge](/badges/ppajer-php-request/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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