phasync/file-streamwrapper

使phasync协程中的文件I/O操作异步。

1.0.0-rc1 2024-05-18 17:27 UTC

This package is auto-updated.

Last update: 2024-09-09 19:31:05 UTC


README

phasync/file-streamwrapper是一个PHP包,当在phasync协程中使用时,它可以使所有的磁盘I/O操作异步化,从而提高I/O密集型任务的效率。此包允许你异步执行文件操作,如读取和写入文件。

安装

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

composer require phasync/file-streamwrapper

使用方法

安装此包时,phasync协程内会自动启用异步文件:// IO。它不会干扰协程外的I/O。

示例

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

<?php

require 'vendor/autoload.php';

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

    phasync::go(function() {
        $data = file_get_contents("other-path");
        // Handle the data
        echo "Data from other-path: " . $data . PHP_EOL;
    });
});

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

许可证

此包是开源的,并受MIT许可证的许可。

贡献

欢迎贡献!请提交pull请求或打开问题报告任何错误或功能请求。

联系

如有任何问题或询问,请在该GitHub存储库中打开问题。