PHPackages                             nggit/php-simple-client - 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. nggit/php-simple-client

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

nggit/php-simple-client
=======================

A Simple and Fast HTTP Client

v1.0(5y ago)21121MITPHPPHP &gt;=5.3.0

Since Mar 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nggit/php-simple-client)[ Packagist](https://packagist.org/packages/nggit/php-simple-client)[ Docs](https://github.com/nggit/php-simple-client)[ RSS](/packages/nggit-php-simple-client/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Simple Client
=================

[](#php-simple-client)

A Simple and Fast HTTP Client, designed to be out of the box. There is also a [simpleclient](https://github.com/nggit/simpleclient) written in Python.

Quick Start
-----------

[](#quick-start)

There are two versions, using cURL or native PHP Stream.

### 1. cURL version

[](#1-curl-version)

```
require 'src/Curl.php';
$client = new Nggit\PHPSimpleClient\Curl();
```

### 2. stream\_socket\_client version (fsockopen variant)

[](#2-stream_socket_client-version-fsockopen-variant)

```
require 'src/Stream.php';
$client = new Nggit\PHPSimpleClient\Stream();
```

You can just use a stand-alone PHP file like that, or use a [wrapper class](src/Client.php). At first, install it via composer:

```
composer require nggit/php-simple-client

```

Then, you can do something like this:

```
require __DIR__ . '/vendor/autoload.php';
use Nggit\PHPSimpleClient\Client;

$client = Client::create(); // default backend is 'stream'
$client = Client::create('curl'); // if you want to use the 'curl' backend
// alternative way:
$client = (new Client())->stream();
// you can also use the options:
$client = (new Client(['debug' => true, 'timeout' => 60]))->curl();
$client = (new Client())->curl(true, -1, 60); // debug, maxredirs, timeout
```

Example
-------

[](#example)

### Simple GET

[](#simple-get)

```
$client->setUrl('https://www.google.com/') // required to set an url
       ->send();

echo $client->getHeader();
# HTTP/1.1 200 OK
# Date: Mon, 11 Feb 2019 07:18:28 GMT
# Expires: -1
# Cache-Control: private, max-age=0
# Content-Type: text/html; charset=UTF-8
# ...

echo $client->getHeader(0);
# HTTP/1.1 200 OK

echo $client->getHeader('Content-Type');
# text/html; charset=UTF-8

print_r($client->getHeaders()); // array

echo $client->getBody();
# ...
```

### Custom Request Method (Optional)

[](#custom-request-method-optional)

The fastest method to get only header is to use HEAD request.

```
$client->setUrl('https://www.google.com/') // required to set an url
       ->request('HEAD')
       ->send();
```

### Setting Headers To Be Sent

[](#setting-headers-to-be-sent)

Setting Headers must be done before calling `request()` and `send()`.

```
$headers = array(
    'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language: en-US,en;q=0.5'
);

$client->setHeaders($headers);
```

### Common

[](#common)

```
echo $client->getProtocol();        # HTTP
echo $client->getProtocolVersion(); # 1.1
echo $client->getStatusCode();      # 200
echo $client->getReasonPhrase();    # OK
```

### Page Redirects

[](#page-redirects)

PHP Simple Client has its own mechanism for handling page redirects without relying on *php.ini*. You can control max allowed redirection via `$client->setMaxRedirs($number)`. $number = 0 means don't allow redirects and **-1** means unlimited redirects (default).

### Cookies

[](#cookies)

No worries. Look at the example below to log in to Facebook.

```
$url = 'https://mbasic.facebook.com/login/device-based/regular/login/?next=https%3A%2F%2Fmbasic.facebook.com%2Fmessages';
$client->setUrl($url);
$client->setHeaders($headers); // you can use headers above
$client->request('POST', array('email' => 'YOUR_USER_NAME_OR_EMAIL', 'pass' => 'YOUR_PASSWORD'));
$client->send(); // send the request

echo $client->getBody(); // display the last page of redirects
```

Advanced
--------

[](#advanced)

There are some hidden features to hack like `getResponse()` to view history of redirection.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1899d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/699c5beda021efaa5c25ebdb7d9c48a785020b578621d99c3d4158c7bb8cad79?d=identicon)[nggit](/maintainers/nggit)

---

Top Contributors

[![nggit](https://avatars.githubusercontent.com/u/12218311?v=4)](https://github.com/nggit "nggit (21 commits)")

### Embed Badge

![Health badge](/badges/nggit-php-simple-client/health.svg)

```
[![Health](https://phpackages.com/badges/nggit-php-simple-client/health.svg)](https://phpackages.com/packages/nggit-php-simple-client)
```

###  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)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

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

78026.4M414](/packages/react-http)[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)

PHPackages © 2026

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