Why PHP 7 yield from still single thread and blocking thread?

From: Date: Mon, 07 Dec 2015 07:05:45 +0000
Subject: Why PHP 7 yield from still single thread and blocking thread?
Groups: php.internals 
Request: Send a blank email to internals+get-89688@lists.php.net to get a copy of this message
As the RFC said. https://wiki.php.net/rfc/generator-delegation The defining feature of Generator functions is their support for suspending execution for later resumption. This capability gives applications a mechanism to implement asynchronous and concurrent architectures even in a traditionally single-threaded language like PHP. With simple userland task scheduling systems interleaved generators become lightweight threads of execution for concurrent processing tasks. I wrote a small test. to see if it really concurrent processing any tasks. the result looks bad. Still single blocking thread. <?php function delayYield() { $delay = mt_rand(1, 5); echo "Delay $delay seconds" . PHP_EOL; sleep($delay); yield date('Y-m-d H:i:s'); } function demoYield() { yield from delayYield(); yield from delayYield(); yield from delayYield(); return delayYield(); } foreach (demoYield() as $v) { echo $v . PHP_EOL; } the executed result: Delay 3 seconds 2015-12-07 07:04:12 Delay 4 seconds 2015-12-07 07:04:16 Delay 1 seconds 2015-12-07 07:04:17 What is concurrent processing as you know? http://docs.hhvm.com/hack/async/introduction HHVM async described well . Appreciate your time. ---------------------------- Netroby

« previous php.internals (#89688) next »