charm/streams 问题修复 & 功能扩展

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

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

charm/streams

Composer 安装命令:

composer require charm/streams

包简介

Various utilities to work with streams and resources in PHP.

README 文档

README

Create readable and writable resource streams. This library uses php stream wrappers to create programmed stream resources.

Readable stream

/**
 * @var resource
 */
$bottlesOfBeer = Charm\Streams\GeneratorStreams::fromGenerator(function() {
    // Yield READ_ONLY, WRITE_ONLY or READ_WRITE mode before
    yield Charm\Streams\GeneratorStreams::READ_ONLY;

    $numberBottles = 99;
    while ($numberBottles > 1) {
        yield $numberBottles . " bottles of beer on the wall<br>\n";
        yield echo $numberBottles . " bottles of beer<br>\n";
        yield "If you take one down<br>\n";
        yield "And pass it around<br>\n";
        $numberBottles = $numberBottles - 1;
        yield "There'll be " . $numberBottles . " bottles of beer on the wall.<br><br>\n";
    }
    yield "Just " . $numberBottles . " bottle of beer on the wall<br>\n";
    yield "Just " . $numberBottles . " bottle of beer<br>\n";
    yield "If you take it down<br>\n";
    yield "And pass it around<br>\n";
    yield "There'll be no more bottles of beer on the wall.<br><br>\n";
});


while (!feof($bottlesOfBeer)) {
    $line = fgets($bottlesOfBeer);
    echo $line;
}

Writable stream

/**
 * @var resource
 */
$log = Charm\Streams\GeneratorStreams::fromGenerator(function() {
    yield Charm\Streams\GeneratorStreams::WRITE_ONLY;

    while (false !== ($data = yield)) {
        echo "Received: ".trim($data)."\n";
    }
});

fwrite($log, "This goes to the log somehow");
fclose($log);

Seekable stream

/**
 * @var resource
 */
$seekableReadStream = Charm\Streams\GeneratorStreams::fromGenerator(function() {
    yield Charm\Streams\GeneratorStreams::READ_ONLY | Charm\Streams\GeneratorStreams::SEEKABLE;

    $offset = 0;
    $data = 'This is some data for a seekable stream';

    // Bucket is passed back and forth and carries messages and strings
    $bucket = null;

    while (false !== ($bucket = yield $bucket) {

        switch (gettype($bucket)) {
            case 'null' :
                // Emit a chunk and update offset
                $bucket = substr($data, $offset, 4);
                $offset += 4;
                break;

            case 'int' : 
                if ($bucket >= 0) {
                    // Update offset
                    $offset = $bucket;
                    $bucket = null;
                    break;
                }
            default :
                // negative integers (they are reserved instructions) and strings are ignored
                $bucket = null;
                break;
        }
    }
});

FIFO stream
-----------

/**

  • @var resource */ $fifo = Charm\Streams\GeneratorStreams::fromGenerator(function() { yield Charm\Streams\GeneratorStreams::READ_WRITE;

    $bucket = null while (false !== ($bucket = yield $bucket)) {

     switch (gettype($bucket)) {
         case 'null' :
             // null means we have nothing, so we'll just yield it
         case 'string' :
             // bucket contains the data we are supposed to serve
             break;
         case 'int' :
             if ($bucket >= 0) {
                 // We don't support seeking
                 $bucket = null;
                 break;
             }
         default :
             $bucket = null;
             break;           
     }
    

    } });

echo fread($fifo, 4096); // '' - empty string returned fwrite($fifo, 'String is no longer empty'); echo fread($fifo, 4096); // 'String is no longer empty'

feof($fifo); // true, unless fclose($fifo) is called


charm/streams 适用场景与选型建议

charm/streams 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 charm/streams 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 charm/streams 我们能提供哪些服务?
定制开发 / 二次开发

基于 charm/streams 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-01