PHP code example of moebius / coroutine
1. Go to this page and download the library: Download moebius/coroutine library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
moebius / coroutine example snippets
use Moebius\Coroutine as Co;
$coroutine = Co::go(function() {
Co::sleep(10);
return true;
});
$coroutine->then(function() {
echo "Done\n";
});
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: