PHPackages                             xuhaoxian/xhx-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. xuhaoxian/xhx-request

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

xuhaoxian/xhx-request
=====================

基于curl封装的http请求器

1.0.0(8y ago)113MITPHPPHP &gt;=7.0.0

Since May 10Pushed 8y agoCompare

[ Source](https://github.com/xuhaoxian/XHXRequest)[ Packagist](https://packagist.org/packages/xuhaoxian/xhx-request)[ RSS](/packages/xuhaoxian-xhx-request/feed)WikiDiscussions master Synced today

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

XHXRequest
==========

[](#xhxrequest)

php写的基于curl封装的http请求器
---------------------

[](#php写的基于curl封装的http请求器)

特点：

1. 支持成功http\_code设置
2. 成功失败回调都用闭包形式
3. 支持失败重试功能，重试次数可以设置

示例代码
----

[](#示例代码)

```
//简单请求，成功回调 闭包形式
XHXRequest::getInstance()->request($url, 'get', array(),
            function (Response $response){
                $res = $response->getBody();
                $this->res = json_decode($res, true);
                return $res;
            });

//成功、失败、完成回调处理 并返回结果
$result = XHXRequest::getInstance()->request($url, 'get', array(),
            function (Response $response){
                $res = $response->getBody();
                $this->res = json_decode($res, true);
                return $res;
            }，
            function (Response $response){
                return 'request fail';
            },
            function (Response $response){
                return 'request complete';
            });

var_dump($result);

//成功返回
[
    'code'=>1,
    'errorCallbackReturn'=>null,
    'successCallbackReturn'=>[...],
    'completeCallbackReturn'=>'request complete'
]

//失败返回
[
    'code'=>0,
    'errorCallbackReturn'=>'request fail',
    'successCallbackReturn'=>null,
    'completeCallbackReturn'=>'request complete'
]

```

全局参数设置
------

[](#全局参数设置)

```
//设置失败重试次数
XHXRequest::getInstance()->retryTimes = 3;

//设置curlOpt
XHXRequest::getInstance()->curlOpt = [];

//设置请求头部
XHXRequest::getInstance()->header = [];

//设置成功的 http_code
XHXRequest::getInstance()->successCode = ['200', '201'];

```

©

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

2924d ago

### Community

Maintainers

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

---

Top Contributors

[![xuhaoxian](https://avatars.githubusercontent.com/u/20789858?v=4)](https://github.com/xuhaoxian "xuhaoxian (10 commits)")

### Embed Badge

![Health badge](/badges/xuhaoxian-xhx-request/health.svg)

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