CKTIS / PHP
Asynchrony and concurrency
A scheduler can interleave tasks by starting fibers and resuming only suspended ones.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
Fiber::suspend(); $task->resume();A scheduler can interleave tasks by starting fibers and resuming only suspended ones. A fiber yields control cooperatively, so code runs uninterrupted until it suspends, returns or throws. This alone provides neither parallel CPU execution nor nonblocking I/O. A blocking operation can stall all tasks on the thread.
$log=[]; $make=function($name)use(&$log){return new Fiber(function()use($name,&$log){$log[]=$name."1";Fiber::suspend();$log[]=$name."2";});};
$jobs=[$make("a"),$make("b")];foreach($jobs as $job)$job->start();foreach($jobs as $job)if($job->isSuspended())$job->resume();echo json_encode($log);
["a1","b1","a2","b2"]
Examples
<?php
$log=[]; $make=function($name)use(&$log){return new Fiber(function()use($name,&$log){$log[]=$name."1";Fiber::suspend();$log[]=$name."2";});};
$jobs=[$make("a"),$make("b")];foreach($jobs as $job)$job->start();foreach($jobs as $job)if($job->isSuspended())$job->resume();echo json_encode($log);
Result
["a1","b1","a2","b2"]