An open API service indexing awesome lists of open source software.

https://github.com/netgusto/co

PHP implementation of tj/co
https://github.com/netgusto/co

Last synced: 10 months ago
JSON representation

PHP implementation of tj/co

Awesome Lists containing this project

README

          

# co

PHP implementation of [tj/co](https://github.com/tj/co). Uses [generator functions](http://php.net/manual/en/language.generators.overview.php) and co-routines (php>=5.5.0) to handle asynchronicity in an apparently synchronous manner.

## Install

```bash
composer require netgusto/co
```

## Example

```php
'Hello World from co !', 'asyncdata' => $data];
};

$http->on('request', function($req, $res) use (&$gen) {
co::run($gen)->then(function($value) use(&$req, &$res) {
$res->writeHead(200, ['Content-Type' => 'application/json']);
$res->end(json_encode($value));
});
});

echo "Magic happens on http://localhost:3000\n";

$socket->listen(3000);
$loop->run();
```