Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113577 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99393 invoked from network); 16 Mar 2021 20:39:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 20:39:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5ED901804DC for ; Tue, 16 Mar 2021 13:32:57 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 16 Mar 2021 13:32:56 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id CFDCAE17 for ; Tue, 16 Mar 2021 16:32:54 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 16 Mar 2021 16:32:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8g+s13 bvNEKurrQlWvIIqSp5lCaLNQa+dCiS2AEA1t4=; b=LfOoThX9CiwdRjN5ti1TpC lojSxwdKZ22z2vgcmvMGHA75OlHTIGv8lpp//W7eiNGcrTr21HlbAdivMkiZb9UK E7d66q4dbzLvcwA2TyxenyWftC5+Q0VBWjAU/rdz1lgnw8gGVtSTFFY6P40AOce4 wy5tNU7s5uV7ITcd65lq5VO4rtSVT4qCi+ViN4lcQvgqK7uj2Rdf6mTWZZzC2SKG q/RFy1jRRBCF4Tbd1Nz3kMFK87JHZlw4wdCQydtqrCMN+3hoxCaN6zFjMGG4d1oX v0X2S2Km+TkL+kdw66aGE+uRr6XkaK7RU4qukRXIoQm6QdTupOZVFY0y8t2hdDvA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefvddgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 249023A0493; Tue, 16 Mar 2021 16:32:54 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-206-g078a48fda5-fm-20210226.001-g078a48fd Mime-Version: 1.0 Message-ID: In-Reply-To: References: <70951423-5e77-c150-6dce-dd3c62f8dc8b@php.net> <0b994a60-7970-605b-1657-d6ee732690e5@gmx.de> <5C73A1DE-E563-4F69-B8C7-6506F81D7345@trowski.com> Date: Tue, 16 Mar 2021 15:32:27 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [VOTE] Fibers From: larry@garfieldtech.com ("Larry Garfield") On Tue, Mar 16, 2021, at 1:44 PM, Josh Di Fabio wrote: > Perhaps we could rather make fibers *opt in* at the *callsite* > (similar to goroutine calls) in order to prevent functions > unexpectedly being executed asynchronously due to faraway changes. > This would be safe and predictable while also avoiding the "What color > is your function" problem. For example > > private function capturePayment(): void > { > $paymentRequest = preparePaymentRequest($this->currentOrder); > // allow, but don't require, the underlying call to use > fibers. Callers higher up the stack would also have to opt in > async $this->paymentGateway->capturePayment($paymentRequest); > > $this->currentOrder->setTransactionId($paymentRequest->getTransactionId()); > } > > With this approach, APIs we'd avoid the "what colour is your function" > problem without sacrificing the safety that we really need in e.g. > ecommerce. "Callers higher up the stack would also have to opt in" is precisely and specifically the design flaw that fibers avoid. What you're suggesting is that a given IO call would become magically non-blocking iff its entire parent call stack was called with `async` keywords, which could be 50 stack frames easily. Aside from the implementation challenge, and the fact that it would require two different code paths even in the PHP code around that IO, even if it could be implemented it would mean that basically no IO code would ever run async, ever, because there is one function call somewhere in the stack that didn't include `async` in some library that everyone uses but hasn't been updated to prefix every single function call with `async`. That is literally the "What color is your function" problem. I should also note that if you are following good practices to begin with, your code base is 90% pure, immutable functions/methods and so entirely safe from cooperative multitasking race conditions. If that's not the case, you have a buggy codebase already even without fibers. Fibers would just make it more obvious. --Larry Garfield