Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112542 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18302 invoked from network); 17 Dec 2020 20:12:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Dec 2020 20:12:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A73D21804C6 for ; Thu, 17 Dec 2020 11:43:39 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mercury.negativeion.net (mercury.negativeion.net [199.38.81.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 17 Dec 2020 11:43:38 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 3352920BA827DD; Thu, 17 Dec 2020 14:43:38 -0500 (EST) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jl-wOCnAae_2; Thu, 17 Dec 2020 14:43:37 -0500 (EST) Received: from [10.0.1.101] (unknown [173.225.146.47]) by mercury.negativeion.net (Postfix) with ESMTPSA id A117120BA827CD; Thu, 17 Dec 2020 14:43:37 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: Date: Thu, 17 Dec 2020 13:43:36 -0600 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <461ED1D8-45CF-431C-91BA-959EF511CBBD@trowski.com> References: To: Peter Stalman X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] [RFC] Fibers From: aaron@trowski.com (Aaron Piotrowski) Hi Peter, > On Dec 17, 2020, at 1:23 PM, Peter Stalman wrote: >=20 > Hi Aaron, this is very interesting to me. Can I ask why this approach = as > opposed to other paradigms like promises, coroutines, etc? You = mentioned > async/await in the future scope, and I assume most of these patterns = can be > implemented once there is an underlying functionality. Basically, why > fibers instead of x? Promises result in the =E2=80=9CWhat color is your function=E2=80=9D = problem as described in the introduction of the RFC. Returning promises = from functions means that functions calling those functions must also = return promises, resulting in the entire call stack needing to return = promises. Fibers are a method of implementing coroutines or interruptible = functions. Promises likely would still be used as placeholders in = libraries using fibers, but coroutines written using fibers do not have = to return another placeholder. Fibers allow async code to be = indistinguishable from sync code, as opposed to an approach where async = functions must return a promise. >=20 > You also mentioned this isn't really intended to be used directly, but = with > a library such as AMPHP. IS the expectation that non-blocking I/O > functionality like database drivers and file operation be provided by > libraries as well? >=20 Since most code written for PHP is blocking, yes, such = libraries/frameworks would need to provide functionality such as = database drivers. Both AMPHP and ReactPHP already have existing async = drivers available for several different popular database systems. = AMPHP=E2=80=99s postgres, mysql, and redis drivers already have a = version using fibers. > I hope I don't come off as critical, I am merely curious. Thank you = for > pushing this forward, as async is something PHP has been lacking and = should > have IMO to compare favourably to other alternatives that do. >=20 You didn=E2=80=99t com off as critical at all! These were good questions = to ask. I too think if PHP is to add support for async code it should = compare favorably to other languages. I think fibers offer a distinct = advantage to using promise for async code. Cheers, Aaron Piotrowski=