定制 moebius/coroutine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

moebius/coroutine

Composer 安装命令:

composer require moebius/coroutine

包简介

Easy to use coroutines for PHP.

README 文档

README

True "green threads" (coroutines) for PHP 8.1. No plugins needed. Coroutines are like multitasking, but without many of the subtle problems that come from threads.

Compatability

Moebius runs other event loops cooperatively; if you are using React, Moebius will run the React Event loop, if you are using Amp, Moebius will run the Amp event loop.

TIP! To make compatible event-loop based applications, you can implement against the moebius/loop implementation yourself.

Essentials

A coroutine is a function which runs in parallel with other code in your application. You can work with coroutines the same way you work with promises in frameworks like React or Amp. In fact, you can use most promise based libraries with Moebius.

Conceals the promises

The main purpose of moebius is to conceal the existence of promises; you should not have to think about coroutines being a part of your application. The only time you need to think about coroutines, is when you need to do multiple things in parallell.

Moebius allows your application to handle multiple requests in parallel, but your program flow should not have to worry about that.

A Coroutine is a Promise

When you create a coroutine, you get a promise about a future result. That future result can be accessed via the then() method, just like any other promise object you're used to.

<?php
use Moebius\Coroutine as Co;

$coroutine = Co::go(function() {
    Co::sleep(10);
    return true;
});

$coroutine->then(function() {
    echo "Done\n";
});

A Promise is a Coroutine

<?php
use Moebius\Coroutine as Co;
use GuzzleHttp\Client;

function get(string $url) {
    $client = new Client();
    echo "Connecting to '$url'\n";
    $result = $client->getAsync($url);
    echo "Got response from '$url'\n";
}

$google = Co::go(get(...), 'https://www.google.com');
$bing = Co::go(get(...), 'https://www.bing.com');
$ddg = Co::go(get(...), 'https://www.duckduckgo.com');



## Examples

You can find complete examples in the `examples/` folder. Here is a trivial example
that reads lines from multiple files concurrently:

moebius/coroutine 适用场景与选型建议

moebius/coroutine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 871 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-06