phasync/http-streamwrapper

一个PHP异步HTTP流包装器,用于在PHP中异步执行http://和https://请求。

0.0.1-rc1 2024-05-18 17:19 UTC

This package is auto-updated.

Last update: 2024-09-18 17:56:18 UTC


README

phasync/http-streamwrapper是一个PHP包,当在phasync协程中使用时,它可以使所有HTTP和HTTPS请求透明地异步执行。此包允许您异步执行HTTP操作,如从URL获取数据,提高I/O密集型任务(如Web请求)的效率。

安装

您可以通过Composer安装此包。无需配置,因为它会自动配置自身在协程中启用并在协程外禁用。

composer require phasync/http-streamwrapper

使用方法

安装此包时,phasync协程内部将自动启用异步http://和https://I/O。它不会干扰协程之外的I/O。

示例

以下是如何在phasync协程框架中使用phasync/http-streamwrapper的示例

<?php

require 'vendor/autoload.php';

// Example usage within phasync coroutine framework
phasync::run(function() {
    phasync::go(function() {
        $data = file_get_contents("http://example.com");
        // Handle the data
        echo "Data from http://example.com: " . $data . PHP_EOL;
    });

    phasync::go(function() {
        $data = file_get_contents("https://example.com");
        // Handle the data
        echo "Data from https://example.com: " . $data . PHP_EOL;
    });
});

在此示例中,使用file_get_contents在phasync协程中异步获取两个URL。自定义流包装器确保这些HTTP操作是非阻塞且高效的。

许可证

此包是开源的,并使用MIT许可证授权。

贡献

欢迎贡献!请提交拉取请求或为任何错误或功能请求创建问题。

联系方式

如有任何问题或查询,请在此GitHub仓库中创建问题。