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
- Host: GitHub
- URL: https://github.com/netgusto/co
- Owner: netgusto
- Created: 2015-07-01T12:33:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T13:15:51.000Z (over 8 years ago)
- Last Synced: 2025-01-29T02:44:39.463Z (12 months ago)
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
```