Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85424 invoked from network); 7 Dec 2015 10:24:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Dec 2015 10:24:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.161 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.161 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.161] ([81.169.146.161:60991] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/DD-55814-55E55665 for ; Mon, 07 Dec 2015 05:24:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1449483859; l=4615; s=domk; d=kelunik.com; h=Content-Type:Cc:To:From:Subject:Date:References:In-Reply-To: MIME-Version; bh=FP6dEujFVCndjKA9sY1PmLMW1cabdztnh7v7k9uHC6s=; b=RF95WdetXxA5afz9LMvMHc4q58Y4dREuo137tFIe+oi6mceR1Ninfsud0ALHu/KUFH1 wWyMADuZKYvkLTu5lq65h9JFlOgjNH39ZfmGNFlwa6vVcnQY912ltUxrJ/1pt9P8r/Ukr dkFC7KvHxG3aPZKbGUQNHSb0IzchQMFltZ8= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3E6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f42.google.com ([74.125.82.42]) by smtp.strato.de (RZmta 37.14 AUTH) with ESMTPSA id e06e0drB7AOIVT8 (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Mon, 7 Dec 2015 11:24:18 +0100 (CET) Received: by wmec201 with SMTP id c201so158181311wme.0 for ; Mon, 07 Dec 2015 02:24:18 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.194.171.97 with SMTP id at1mr32012549wjc.39.1449483858784; Mon, 07 Dec 2015 02:24:18 -0800 (PST) Received: by 10.194.22.5 with HTTP; Mon, 7 Dec 2015 02:24:18 -0800 (PST) In-Reply-To: References: Date: Mon, 7 Dec 2015 11:24:18 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Netroby Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e013c615082ba7805264c4210 Subject: Re: [PHP-DEV] Why PHP 7 yield from still single thread and blocking thread? From: me@kelunik.com (Niklas Keller) --089e013c615082ba7805264c4210 Content-Type: text/plain; charset=UTF-8 Hi Netroby, > I wrote a small test. to see if it really concurrent processing any tasks. > the result looks bad. Still single blocking thread. > As the RFC already states: The actual implementation of coroutine task schedulers is outside the scope > of this document. This RFC focuses only on the language-level machinery > needed to make such tools more feasible in userland. It should be obvious > that simply moving code into a generator function will not somehow make it > magically concurrent. You need a task scheduler like Amp (https://github.com/amphp/amp). With Amp, you code would look like: > function delayYield() { > $delay = mt_rand(1, 5); > echo "Delay $delay seconds" . PHP_EOL; > yield new Amp\Pause($delay * 1000); // <-- Note: It's not using a > synchrnous sleep here! > return date('Y-m-d H:i:s'); > } > > Amp\run(function() { > $promises = []; > for ($i = 0; $i < 3; $i++) { > $promises[] = Amp\resolve(delayYield()); // turns the generator > into a promise so they're combinable with Amp\all > } > $dates = yield Amp\all($promises); > }); > yield from is more to factor larger functions into smaller units than directly for doing tasks asynchronously. Regards, Niklas --089e013c615082ba7805264c4210--