Download the PHP package yunadmin/http-client without Composer

On this page you can find all versions of the php package yunadmin/http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-client

yunadmin/http-client

Packagist Version PHP Version Stars Issues

仓库:https://github.com/yunadmin-cn/http-client
安装:composer require yunadmin/http-client

零依赖、轻量级的 PHP HTTP 客户端。仅依赖 PHP ≥ 8.0 的原生扩展(curl / json),无任何 Composer 第三方包。


特性

能力 说明
双引擎 cURL (CurlHandler) / Socket Stream (StreamHandler) 自动选择
异步并发 CurlMultiHandler 基于 cURL Multi;Future、requestAsync()、pool()(并发度控制)
流式上传 按 8KB chunk 读取 body,未知长度自动走 Transfer-Encoding: chunked,大文件友好
中间件系统 HandlerStack 管道;内置重定向、HTTP 错误抛出、指数退避重试、历史记录
Cookie 会话 CookieJar + 标准 Set-Cookie 解析(支持引号内嵌分号)
可测试 MockHandler 响应队列 + HistoryMiddleware 历史记录,不发真实请求即可测业务
常用选项对齐 decode_content、force_ip_resolve、timeout、connect_timeout、verify、cert/ssl_key、proxy、auth、on_stats、sink、json/form_params/multipart/body、query、base_uri、curl
PSR-7 风格对象 Request / Response / Uri / Stream / StreamInterface

要求:php ^8.0、ext-curl、ext-json(已在 composer.json 声明)。


安装

或手动引入:只需注册 PSR-4 前缀 Yunadmin\HttpClient\ 指向 src/,并 require 'src/functions.php'。


1. 快速开始


2. HTTP 方法

便捷方法:get / head / post / put / patch / delete / options,每个都接受 (uri, options)。

对应异步版:getAsync / postAsync / putAsync / patchAsync / deleteAsync / requestAsync,返回 Future(见第 6 节)。


3. 请求体:JSON / 表单 / 文件上传

3.1 JSON(json)

3.2 URL 编码表单(form_params)

3.3 multipart 表单 & 文件上传(multipart)

说明:

3.4 原始 body(body)


4. URI 处理

4.1 base_uri + 相对 URI

4.2 query 选项

4.3 Uri 类(PSR-7 风格)


5. 认证、代理、超时、TLS


6. 异步 & 并发(cURL Multi)

6.1 getAsync / postAsync / requestAsync → 返回 Future

6.2 Future 链式回调

链式回调会在 wait() 时按顺序执行(轻量实现,不依赖 Promise/A+ 库)。

6.3 pool() — 大列表 + 并发度控制

$requests 每一项支持:


7. 重定向、HTTP 错误、重试

7.1 重定向(allow_redirects)

内置 RedirectMiddleware;超过 max 抛 TooManyRedirectsException。

7.2 HTTP 错误(http_errors)

默认 4xx / 5xx 会抛异常:

关闭:new Client(['http_errors' => false]),自己判断 getStatusCode()。

7.3 重试(指数退避,retry)

关闭:'retry' => false。


8. Cookie 会话(CookieJar)

CookieJar 常用方法:

Set-Cookie 解析器支持:引号内含分号的 value(例如 tk="abc;foo=bar"; Path=/api),不会被错误切断。

单次请求也可以直接传非 Jar 的 cookies:


9. sink 下载、on_stats 统计、调试

9.1 文件下载(sink)

使用 sink 后,$resp->getBody() 会被清空(返回空字符串),避免内存保留一份。

9.2 on_stats 统计回调

9.3 debug:输出 HTTP 原始报文

9.4 全局 http_* 快捷函数

这些函数会复用同一个静态 Client 实例。


10. 可测试:Mock + 历史记录


11. 自定义中间件 & HandlerStack

每个中间件签名:callable(RequestInterface, array): (ResponseInterface|FutureInterface)。


12. 选项速查表

选项 类型 说明
base_uri string / UriInterface 相对 URI 基准
handler HandlerStack / HandlerInterface 自定义底层或中间件栈
timeout / connect_timeout float 总 / 连接超时秒(<1 可用)
verify bool / string false 关校验,或 CA 文件/目录
cert / ssl_key string / [path, pass] 客户端证书/私钥
proxy string / [http,https,no] 代理;no 为不走代理的域名数组
force_ip_resolve 'v4' / 'v6' / null 强制 IPv4/6
decode_content bool 默认 true:自动压缩&解压
auth [u,p] / [t,'','bearer'] / string Authorization 头
headers array 合并进请求头
query array / string 追加到 URI query
json mixed JSON 请求体
form_params array URL 编码表单
multipart array [{name, contents, filename?, headers?}, ...]
body string / resource / StreamInterface 原始请求体
cookies CookieJar / array / string Jar=会话保持;其他=单次
allow_redirects bool / [max,strict,keep_body] 重定向控制
http_errors bool 默认 true,4xx/5xx 抛异常
retry false / [retries,delay,multiplier,when?] 指数退避重试
on_stats callable(object) 请求完成统计回调
sink string / resource 响应体直接写文件/流
debug bool / resource 原始 HTTP 报文输出
curl [CURLOPT_* => v] CurlHandler 直接追加 CURLOPT

13. 目录结构

版本要求


All versions of http-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
ext-curl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yunadmin/http-client contains the following files

Loading the files please wait ...