3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* A tasks job is to count from 0 to $limit */ class Task { public function __construct($limit) { $this->limit = ($limit + 1) * 100; } public function doWork() { $this->position++; } public function hasWork() { return $this->position <= $this->limit; } public function getPosition() { return $this->position; } private $position = 0; private $limit = 0; } /* create three tasks */ $tasks[] = new Task(0); $tasks[] = new Task(1); $tasks[] = new Task(3); /* do some work */ function work($tasks) { foreach ($tasks as $task) if ($task->hasWork()) $task->doWork(); } /* detect more work to do */ function finished($tasks) { foreach ($tasks as $task) { if ($task->hasWork()) return false; } return true; } /* helper for printing positions */ function positions($tasks) { $positions = []; foreach ($tasks as $task) { $positions[] = $task->hasWork() ? $task->getPosition() : "-"; } return $positions; } /* execute tasks asynchronously */ while (!finished($tasks)) { vprintf( "% 4s % 4s % 4s\n", positions($tasks)); work($tasks); } ?>

preferences:
50.79 ms | 402 KiB | 5 Q