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 2w ago

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 36% 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

2973d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20789858?v=4)[许豪贤](/maintainers/xuhaoxian)[@xuhaoxian](https://github.com/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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.6k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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