PHPackages                             php-comp/http-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. php-comp/http-client

Abandoned → [phppkg/http-client](/?search=phppkg%2Fhttp-client)Library[HTTP &amp; Networking](/categories/http)

php-comp/http-client
====================

simple http client library of the php

v3.0.2(3y ago)31.5kMITPHPPHP &gt;8.0.0CI failing

Since Nov 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/phppkg/http-client)[ Packagist](https://packagist.org/packages/php-comp/http-client)[ Docs](https://github.com/phppkg/http-client)[ RSS](/packages/php-comp-http-client/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (9)Dependencies (2)Versions (17)Used By (0)

HTTP Client
===========

[](#http-client)

[![License](https://camo.githubusercontent.com/50e624328442ffb01dba3c303ea1c71f4c7f83dae8d189e9adf26babdf0d7420/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706870706b672f687474702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/06c26169ff2cd57b46146ad93d5a303c03579cc46cb6d8e274a39dddd56e337a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706870706b672f687474702d636c69656e743f6d61784167653d32353932303030)](https://packagist.org/packages/phppkg/http-client)[![Latest Stable Version](https://camo.githubusercontent.com/9c33bd3298a19343ae1db467e1ef3c10c451b0fbfc9a9171509eafc1b13edae8/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870706b672f687474702d636c69656e742e737667)](https://packagist.org/packages/phppkg/http-client)[![GitHub tag (latest SemVer)](https://camo.githubusercontent.com/2b8f7533e15fad74af9dfed05305a8701ffcee7313a54432f1b8b5d3bdd488a0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f706870706b672f687474702d636c69656e74)](https://github.com/phppkg/http-client)[![Github Actions Status](https://github.com/phppkg/http-client/workflows/Unit-tests/badge.svg)](https://github.com/phppkg/http-client/actions)

An easy-to-use HTTP client library for PHP. Support CURL, file, fsockopen, stream drivers.

- Simple and easy to use HTTP client
- Support drivers: `curl` `swoole` `fsockopen` `stream` `fopen`
- Support all HTTP method. eg: `GET,POST,PATCH,PUT,HEAD,DELETE`
- Support setting proxy, customizing headers, auth, content-type etc.
- Implement interface [PSR 18](https://github.com/php-fig/http-client)

安装
--

[](#安装)

```
composer require phppkg/http-client
```

使用
--

[](#使用)

### 创建客户端实例

[](#创建客户端实例)

**自动选择驱动类**:

```
use PhpPkg\Http\Client\Client;

// use factory
$client = Client::factory([
    'driver' => 'curl', // stream, fsock, fopen, file, co, co2

    // ... 更多选项
    'baseUrl' =>  'http://my-site.com'
]);
```

**直接使用指定的类**:

```
$options = [
  'baseUrl' =>  'http://my-site.com'
  // ...
];
$client = CurlClient::create($options);
$client = FileClient::create($options);
$client = FSockClient::create($options);
$client = FOpenClient::create($options);
$client = CoClient::create($options);
```

### 基本使用

[](#基本使用)

```
use PhpPkg\Http\Client\Client;

$client = Client::factory([]);

$client->get('/users/1');

$post = ['name' => 'john'];
$client->post('/users/1', $post);

// add ajax header
$client->byAjax()->post('/users/1', $post);

// add json content type
$client->json('/users/1', json_encode($post));
// or
$client->byJson()->post('/users/1', json_encode($post));

$statusCode = $client->getStatusCode();
$headers = $client->getResponseHeaders();

// get body data
$data = $client->getResponseBody();
$array = $client->getArrayData();
```

**解析响应Body**:

```
$data = $client->getDataObject();
$data->getInt('createTime', 0);

$user = new User();
$client->bindBodyTo($user);
vdump($user->name);
```

### 文件上传下载

[](#文件上传下载)

- `public function upload(string $url, string $field, string $filePath, string $mimeType = '')`
- `public function download(string $url, string $saveAs)`
- `public function downloadImage(string $imgUrl, string $saveDir, string $rename = '')`

```
$client = CurlClient::create([
  // ...
]);

$client->upload(...);
```

常用方法
----

[](#常用方法)

- `getJsonArray/getArrayData(): array`
- `getJsonObject(): stdClass`
- `getDataObject(): DataObject`
- `bindBodyTo(object $obj): void`

LICENSE
-------

[](#license)

[MIT](LICENSE)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance61

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 80.7% 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 ~125 days

Recently: every ~100 days

Total

13

Last Release

1219d ago

Major Versions

1.x-dev → v2.0.02020-06-10

v2.1.1 → v3.0.02021-12-07

PHP version history (4 changes)v1.0.0PHP &gt;7.0.0

v2.0.0PHP &gt;7.1.1

v2.1.1PHP &gt;7.2.0

v3.0.0PHP &gt;8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (67 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (16 commits)")

---

Tags

curlhttp-clientswoolehttpcurllibrarytoolfopen

### Embed Badge

![Health badge](/badges/php-comp-http-client/health.svg)

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

###  Alternatives

[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48247.0M384](/packages/php-http-curl-client)[voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

16183.9k1](/packages/voku-httpful)[sunrise/http-client-curl

A simple cURL client implementing PSR-18.

187.5k](/packages/sunrise-http-client-curl)

PHPackages © 2026

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