PHP code example of raphaeu / async
1. Go to this page and download the library: Download raphaeu/async 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/ */
raphaeu / async example snippets
// Import
use async\Task;
use async\Async;
// Inicialize async class
$async = new Async();
// Create tasks
$task1 = new Task("php /tmp/randTimer.php");
$task2 = new Task("php /tmp/randTimer.php");
$task3 = new Task("php /tmp/randTimer.php");
// Vinculando testes
$async->addTask($task1);
$async->addTask($task2);
$async->addTask($task3);
// Rodando tarefas assíncronas
while ($totalOk = $async->hasDo())
{
echo "Rodando: ".((count($async->getTasks()) - $totalOk) + 1)."/". count($async->getTasks()) ."\r";
usleep(250);
}
// Pegando resultados das tarefas
foreach ($async->getTasks() as $task)
{
echo PHP_EOL. $task->getResult();
}
sleep(rand(1, 5));
echo time();
$async = new Async('/path-temp/');