edgetelemetrics/fetch 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edgetelemetrics/fetch

最新稳定版本:v0.1.0

Composer 安装命令:

composer require edgetelemetrics/fetch

包简介

Async PHP implementation of the Javascript FetchAPI

README 文档

README

Implementation of the Javascript fetch() API

Features

Supports HTTP/2+3, connection pooling (with keep-alive), and the extraction of timing data for the requests.

Requirements

The package is compatible with PHP 8.2+ and requires the cURL extension and edgetelemetrics/reactphp-http-browser-curl library.

Installation

You can add the library as a project dependency using Composer:

composer require edgetelemetrics/fetch

Examples

See /examples directory. Examples based on examples from reactphp/http under MIT License

Timing

Request timing values are returned in the PSR7 Response object headers under the key Server-Timing

Configuration

The Browser can be configured with standard CURLOPT_* parameters given via the constructor.

fetch(
    $uri,
    [
        'curlOpts' => [
            CURLOPT_TIMEOUT => 20,
            CURLOPT_DOH_URL, 'https://1.1.1.1/dns-query',
            CURLOPT_DNS_SERVERS => '1.1.1.1',
        ],
    ]);

Connection Metadata

Connection Timing

The request/response timing is provided though the header 'ServerTiming' in the Response object.

Each timing point is defined as <timing point>;dur=<duration in second>

  • namelookup_time
  • connect_time
  • appconnect_time
  • pretransfer_time
  • redirect_time
  • starttransfer_time
  • total_time

Connection Details

Additional request/response metadata is provided though the header 'X-Connection' in the Response object.

Key/Value pairs are as follows:

  • effective_url=<final url after any redirects>
  • connection;count=<number of connections opened during the request, 0 if existing connection reused>
  • redirect;count=<number of redirects followed>
  • upload;size=<bytes sent in request(headers+body) including redirects>;speed=<overall bytes per second upload>
  • download;size=<bytes received in response(headers+body) including redirects>;speed=<overall bytes per second download>

Synchronous Use

This library can be used in synchronous mode using react\async.

See Synchronous Client Example

License

MIT, see LICENSE file.

Contributing

Bug reports (and small patches) can be submitted via the issue tracker. Forking the repository and submitting a Pull Request is preferred for substantial patches.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-25