Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101810 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79366 invoked from network); 8 Feb 2018 15:55:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2018 15:55:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=i@lvht.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=i@lvht.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lvht.net from 54.254.200.128 cause and error) X-PHP-List-Original-Sender: i@lvht.net X-Host-Fingerprint: 54.254.200.128 smtpbgsg2.qq.com Received: from [54.254.200.128] ([54.254.200.128:41915] helo=smtpbgsg2.qq.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/35-49805-3D27C7A5 for ; Thu, 08 Feb 2018 10:55:01 -0500 X-QQ-mid: bizesmtp7t1518105290t8p0i1xf8 Received: from [192.168.1.4] (unknown [222.71.123.232]) by esmtp4.qq.com (ESMTP) with id ; Thu, 08 Feb 2018 23:54:49 +0800 (CST) X-QQ-SSF: 0110000000400060F750B00A0000000 X-QQ-FEAT: nSUdqPGu3ttxQPpIpr9rxt2IPwZCRtCPNPDjsxDLxCnsrDoP1Fpln3TITNmNi 9kdGWvMqSiFwpo7nrDtmoZw/b1o8oJdYxOQ/cwI/OhPWkkhkxViECiR3xvNthjMJdWkgcbe qFAow0zxki0U+CYwY50L2G63+xR4rfeJUVRG+IdIyyN3ABpI3DCH7E8AziQ32X7aWHPKC65 mnsUr6NEjUyO/aSEh1GEmGhlUrK+A2bWzWozkEGYi7bx1G4vUDMlJU8Uq6/cr93BEBUjUnr VcCzWkANrL3gPN X-QQ-GoodBg: 0 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.9\)) In-Reply-To: <0DDFDACA-6322-461C-9D57-215E8C7D9CD0@trowski.com> Date: Thu, 8 Feb 2018 23:54:49 +0800 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <76EBF900-3BE8-4B60-9422-880A9754FCC4@lvht.net> <0DDFDACA-6322-461C-9D57-215E8C7D9CD0@trowski.com> To: Aaron Piotrowski X-Mailer: Apple Mail (2.3445.6.9) X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lvht.net:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Subject: Re: [PHP-DEV] [RFC] Fiber support (again) From: i@lvht.net (Haitao Lv) > On Feb 8, 2018, at 12:18, Aaron Piotrowski wrote: >=20 >>=20 >> On Feb 7, 2018, at 7:05 PM, Haitao Lv wrote: >>=20 >> Hi internals, >>=20 >> I propose to introduce the Fiber feature AGAIN. >>=20 >> The main purpose of the RFC is to introducing a lightweight stackful = coroutine support for PHP and make it possible to write non-blocking = code in the blocking style. >>=20 >> In this RFC, no new keyword is needed. So it will not break the PHP = 7.3 release. >>=20 >> Please see the RFC https://wiki.php.net/rfc/fiber >>=20 >> Dmitry and I are working on the implementation at = https://github.com/fiberphp/fiber-ext >> And a series of usage demo can be found at = https://github.com/fiberphp/fiber-demo >>=20 >> Please offer you comments. >>=20 >> Thank you. >>=20 >> --- >> Haitao Lv >>=20 >=20 >=20 > Hi Haitao, >=20 > I'm very excited to see this sort of feature coming to PHP. >=20 > A couple of questions and thoughts: >=20 > - How do you determine when a fiber has returned? Looking at the = source, it appears Fiber::status() must be used, comparing against = constants. Separate methods similar to Generator would be better IMO. = e.g.: Fiber::alive(), Fiber::suspended(), Fiber::running() Offering methods like Fiber::alive, Fiber::running makes no difference = to check the Fiber::status() return value. This is just a style issue. = And as a language feature, Fiber only offer the essential API and let other works to the user land. > - What about throwing exceptions into a fiber? Currently does not support throw exception into the fiber. User land = code could check the value of Fiber::yield and throw exception themselves. The Ruby's = Fiber and Lua's coroutine also does not support such api as well. >=20 > - Using Fiber::resume() to initialize the fiber and resume feels = awkward. Separate methods again would be better here, perhaps = Fiber::init(...$args) and Fiber::resume($send). All Fiber created with a suspended status. So make resume to do both the = init and resume do make sense. Please see Ruby Fiber API https://ruby-doc.org/core-2.2.0/Fiber.html. >=20 > - What happens if the sub1() function in the RFC is invoked outside of = a fiber? You will get a Fatal Error like Fatal error: Uncaught Error: Cannot call Fiber::yield out of Fiber > - I think a keyword here would be beneficial, even if it has a minor = BC impact. Fibers could then be written like generators. `await` or = `emit` as a keyword perhaps? This would be a less verbose API, feel less = magical (a static method call that actually pauses execution feels out = of place), and would allow Fibers to be returned from methods, named = functions, etc with less boilerplate. Wishing this to be accepted by the community in the PHP 7.3, so no = keyword is accepted. And if the community cannot accept, the Fiber can be still distributed = as a standalone extension. So we cannot depend on a new keyword. > Thanks to you and Dmitry for working on this! >=20 > Aaron Piotrowski > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php