PHP code example of easyswoole / component
1. Go to this page and download the library: Download easyswoole/component 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/ */
easyswoole / component example snippets
use EasySwoole\Component\CoroutineRunner\Runner;
use Swoole\Coroutine\Scheduler;
use EasySwoole\Component\CoroutineRunner\Task;
$scheduler = new Scheduler;
$scheduler->add(function () {
$runner = new Runner(4);
$i = 10;
while ($i){
$runner->addTask(new Task(function ()use($runner,$i){
var_dump("now is num.{$i} at time ".time());
\co::sleep(1);
if($i == 5){
$runner->addTask(new Task(function (){
var_dump('this is task add in running');
}));
}
}));
$i--;
}
$runner->start();
var_dump('task finish');
});
$scheduler->start();