PHPackages                             hhxsv5/php-coroutine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hhxsv5/php-coroutine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hhxsv5/php-coroutine
====================

A lightweight library to implement coroutine by yield &amp; Generator.

1.3.0(8y ago)272.1k7[1 issues](https://github.com/hhxsv5/php-coroutine/issues)MITPHPPHP &gt;=5.5

Since Aug 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/hhxsv5/php-coroutine)[ Packagist](https://packagist.org/packages/hhxsv5/php-coroutine)[ Docs](https://github.com/hhxsv5/php-coroutine)[ RSS](/packages/hhxsv5-php-coroutine/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

PHP Coroutine
=============

[](#php-coroutine)

A lightweight library to implement coroutine by yield &amp; Generator.

Requirements
------------

[](#requirements)

- PHP 5.5 or later

Installation via Composer([packagist](https://packagist.org/packages/hhxsv5/php-coroutine))
-------------------------------------------------------------------------------------------

[](#installation-via-composerpackagist)

```
composer require "hhxsv5/php-coroutine:~1.0" -vvv
```

Usage
-----

[](#usage)

### Run demo

[](#run-demo)

- PHP 5.5+

```
include '../vendor/autoload.php';

use Hhxsv5\Coroutine\Scheduler;

$start = microtime(true);
/**
 * @param mixed & $return
 * @return Generator
 */
function task1(&$return)
{
    echo 'task1:start ', microtime(true), PHP_EOL;
    $return = yield file_get_contents('http://www.weather.com.cn/data/cityinfo/101270101.html');
    echo 'task1:end ', microtime(true), PHP_EOL;
}

/**
 * @param mixed & $return
 * @return Generator
 */
function task2(&$return)
{
    echo 'task2:start ', microtime(true), PHP_EOL;
    $return = yield file_get_contents('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=yourtoken');
    echo 'task2:end ', microtime(true), PHP_EOL;
}

$scheduler = new Scheduler();

$t1 = task1($return1);
$t2 = task2($return2);

$scheduler->createTask($t1);
$scheduler->createTask($t2);

$scheduler->run();

var_dump($return1, $return2);

$end = microtime(true) - $start;
echo $end;
```

- PHP7+

```
include '../vendor/autoload.php';

use Hhxsv5\Coroutine\Scheduler;

$start = microtime(true);
/**
 * @return Generator
 */
function task1()
{
    echo 'task1:start ', microtime(true), PHP_EOL;
    $ret = yield file_get_contents('http://www.weather.com.cn/data/cityinfo/101270101.html');
    echo 'task1:end ', microtime(true), PHP_EOL;
    return $ret;
}

/**
 * @return Generator
 */
function task2()
{
    echo 'task2:start ', microtime(true), PHP_EOL;
    $ret = yield file_get_contents('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=yourtoken');
    echo 'task2:end ', microtime(true), PHP_EOL;
    return $ret;
}

$scheduler = new Scheduler();

$t1 = task1();
$t2 = task2();

$scheduler->createTask($t1);
$scheduler->createTask($t2);

$scheduler->run();

var_dump($t1->getReturn(), $t2->getReturn());//PHP 7+

$end = microtime(true) - $start;
echo $end;
```

License
-------

[](#license)

[MIT](https://github.com/hhxsv5/php-coroutine/blob/master/LICENSE)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

3195d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25aef9db96e7295dedf20a48e81eb69dcfd3b2cae12859d37aa90c8a6c53e720?d=identicon)[hhxsv5](/maintainers/hhxsv5)

---

Tags

coroutinegeneratoryieldgeneratorcoroutineyieldphp-coroutine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hhxsv5-php-coroutine/health.svg)

```
[![Health](https://phpackages.com/badges/hhxsv5-php-coroutine/health.svg)](https://phpackages.com/packages/hhxsv5-php-coroutine)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k27.6M92](/packages/simplesoftwareio-simple-qrcode)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

745663.8k13](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[symplely/coroutine

Cooperative multitasking using generators. The basics of coroutines, async and await!

621.6k2](/packages/symplely-coroutine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
