Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113575 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94947 invoked from network); 16 Mar 2021 20:14:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 20:14:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ED6A31804DC for ; Tue, 16 Mar 2021 13:07:49 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.22]) (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:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615925267; cv=none; d=strato.com; s=strato-dkim-0002; b=kc3wRsRaEN5+yQpNeH0TnNKBiMSuUFqG+rLpbtePNdTDidoFj2HxOn+Kb6YEat2Gzg zOgKJF+KiuwLVSfBmTLl76Pftx+73awMgVW3u+JY9bKhdtsfYaUxOZkqmUDJMlG+Et9b aZlFwC66d4MNm5D5YPsB6vLWXV6ckn1a9glzieDAjAX5C6yifbake3zST/p17FhnHOqx Ha8NHmZE444pJ+mQ9GP7hklotn5yO+yu0R3tjgRDcNE/Ts9A+EkuB58oliKnj1Qo4IoL UM5a/b2dv/SJsPCzYmYdrPfSDaI4hAHJxgUSfny3GvBfg8zMatAKFa2gQQcoeBhvFXhu R9Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1615925267; s=strato-dkim-0002; d=strato.com; h=Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:Cc:Date: From:Subject:Sender; bh=4l4ftJiMs4Dm/e40Ano7T8A59qb5iiw7svIJF18MGHI=; b=aQn2GfoYDp4icS4pqHo2W1c1UGHCjlNiu7tVmAhAN+I03CLPqqrvF1n//KiyDPMkl6 e5rQkJIVvnmoJoJPf58CGm3wNW61kZukmkF+yOyXNC/yUvDLhTMs/bRWCRVlgRSBhzyM 83stcvRnUldwt1wu86DZjSS8azWBl9Kwd43Ag1wRx/P/LQ11BbOiZy6jV0xwFJwOq79p ZJH4G4nXraafuXfOOPf46l8QFgfH9kZdks7LGdwhfd9B8lcPLSulejMwFL6xvr9AFNmV zPInnf7wPyCLbA322SDpnnBEMHs9RB5G4sG/er+8xfGyLf2J9tpfeGp4VVfkYdgwam6d Mi0Q== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1615925267; s=strato-dkim-0002; d=kelunik.com; h=Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:Cc:Date: From:Subject:Sender; bh=4l4ftJiMs4Dm/e40Ano7T8A59qb5iiw7svIJF18MGHI=; b=lA/qQbYS5t2rimnbO50Po0+QhtcfAvPret890No8u58J3WE08ynwSVS+jGl/a9+sgY Q2xSuiLl5i3Ky4iE08VIaiGzt0PU3kKDQ06KL0Dy7cFmJfr9eQM/U4JC1bf/LXg+FoDF kdHwhhbOi3UfjdsmzP30R9nGk1o5CY5Kl9Xx3iv1RP0Wz2El1zdG0UpEIBpCiuaT7anj Q/ZlaA31eracwgNLY1s+u3hYL7uxx0r09A8bWkofFR/iYegjm9/FSFU/zwPZGQYANq5p w8END4V8XA+/dvws/+FPIeYv9mp9CDf/Udh9e2IdGb82l22ZmDbseLe9CfUNa3Ph6mOZ cA3g== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":IWkkfkWkbvHsXQGmRYmUo9mlsGbEv0XHBzMIJSS+jKTzde5mDb8AaBMcZiAocA==" X-RZG-CLASS-ID: mo00 Received: from mail-pg1-f174.google.com by smtp.strato.de (RZmta 47.21.0 AUTH) with ESMTPSA id j0836ex2GK7k7Mx (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Tue, 16 Mar 2021 21:07:46 +0100 (CET) Received: by mail-pg1-f174.google.com with SMTP id p21so23347948pgl.12 for ; Tue, 16 Mar 2021 13:07:46 -0700 (PDT) X-Gm-Message-State: AOAM531JZYeq0Y5SMhHLG6UCQRT7megvguP2JcD+zc2V2xSzo/3e04hA 8tPXq9C+mKG0oAm+BbaxyZVW40VFtASOsWrC9mk= X-Google-Smtp-Source: ABdhPJz8k3Uj0udQ6+iW/kiU0u7W9cgDKbu6fYjCELZv+JZfpxbh7o0hlFGX3vLR9QpS7gGHlwddnfcxNG9Ac1/xgeY= X-Received: by 2002:a65:6642:: with SMTP id z2mr1223668pgv.214.1615925265550; Tue, 16 Mar 2021 13:07:45 -0700 (PDT) MIME-Version: 1.0 References: <70951423-5e77-c150-6dce-dd3c62f8dc8b@php.net> <0b994a60-7970-605b-1657-d6ee732690e5@gmx.de> <5C73A1DE-E563-4F69-B8C7-6506F81D7345@trowski.com> In-Reply-To: Date: Tue, 16 Mar 2021 21:05:24 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Josh Di Fabio Cc: Aaron Piotrowski , "Christoph M. Becker" , Michael Wallner , php internals , Derick Rethans Content-Type: multipart/alternative; boundary="0000000000006fd3a905bdaceba6" Subject: Re: [PHP-DEV] [VOTE] Fibers From: me@kelunik.com (Niklas Keller) --0000000000006fd3a905bdaceba6 Content-Type: text/plain; charset="UTF-8" Hey Josh, > > This is a very valid concern to have. However, this code won't simply > break if executed asynchronously. > > It only breaks if the same method (or other methods making use of the > same state) is executed concurrently on that object. > > I understand this, but of course this will be common in programs where > fibers are used, and the nature of this proposal means that fibers > will potentially be highly insidious and quite unpredictable in their > reach. > Concurrent operations on stateful, mutable objects are certainly a risk and concurrency shouldn't be introduced without thinking about the consequences. Care must be taken if objects are used across different fibers concurrently, unless you use global state, then you'll have a harder time adding concurrency to your application. > > If you can see the race condition here, you can probably also see the > race condition in the original snippet above. > > The difference is that in the second case, the developer has > *explicitly opted into the underlying call being async*. I.e. they > expect it, and can design with it in mind. > While the developer opted into async / non-blocking I/O, they still might not have thought about concurrent operations on that same object. > Being able to use the type system is a concern the RFC solves, but that's > rather just nice-to-have. The relevant problem is the call stack pollution > or "What color is your function" problem. It simply doesn't make sense for > applications and libraries to offer an async and non-async interface for > everything. Due to the "What color is your function" problem, there can't > be a gradual migration to non-blocking I/O, which will mostly result in > non-blocking I/O simply not being supported by the majority of libraries, > making it basically non-viable in PHP. > > 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. > This doesn't really avoid the "what color is your function" problem, as you'd have to mark all function calls with "async" then, eventually resulting in every PHP function call having to be prefixed with "async". Rather than marking methods with "synchronized" as mentioned before, it might be more feasible to mark methods with a keyword if they allow concurrent operations. I'll have to research which options are viable. Best, Niklas --0000000000006fd3a905bdaceba6--