Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113590 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74361 invoked from network); 17 Mar 2021 14:47:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2021 14:47:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 07B0B180508 for ; Wed, 17 Mar 2021 07:41:06 -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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 ; Wed, 17 Mar 2021 07:41:05 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id s7so885901plg.5 for ; Wed, 17 Mar 2021 07:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Us/pte4UuOVWoIC6hpF7rLyDV7yMp1pU9KkPD5AOihg=; b=I9XkLlfF4ZgPeer8NE7CBMjksySk5pJPR3+O+A4Knk9UvaY9/jyfE26HPYYdWFT/v+ aaHy+VlLGOAMrGEm1XgxWLhCzP0Xr0EI2m/Q0vFM2G3/U+wLKOVHhMDkhcdtyl1bSZhr o01oNh88D9RmaSZrBEFZuEazG3etHRfbB2f873qJcV9ps2YmDa1lMg/cji46y/T+zMgq ioW83MxcB5JQ9uLfnkxH36drcpl/lCsK5BRgb8+XE29UrUX3hgmVNb9QOYLH4oa3Q3q5 FBY1NRQAe5H8B+E7uqnxLDQ4hONP5LQONOgO0qOuOcGIG8Rr0aPFgfA/cbFfIRz2/r1x 3B8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Us/pte4UuOVWoIC6hpF7rLyDV7yMp1pU9KkPD5AOihg=; b=jXrEswbDd1SlYZPug8hxCkvBSYp0F1a+jmbMNubN/cNdy2S6gbEv2d3lNAohbcin+q XLKuDvB/jCjP985V0OxY1rTrw+rbwFSt58d53taw8wCBGe+JXVn63MBhcMxWKETvPx7l wI7z8EKrvkFM0QcyXdfX3iz2LdDG7fgvX8x8E7QKqcgmmsvly+ZDcI4dflthnGWo5PCC /kWpVoK1EfysJwOgBPAe7ruTFK4wmPpST9jU6xNt+0dFmI/qvM8sybl7Zv0NZoXzo1hG n373rk5FjNphgyXhTfiSjqYMT8CfEnToxIwaJn7qpkqQVfYB5XIGfMDiP92InBG/AgX9 bswg== X-Gm-Message-State: AOAM530OC10i9/4SD4UZMy9ZiUasR2Jiv6zyBrwNGBSquEJ6Wb3dpoUR ZiOWSNXx7Cb2PNL5AcJtxhHf3feyKhqeDRTw5o8= X-Google-Smtp-Source: ABdhPJyI9/QZpkMm16TJTfm1MS+en76ax2+1Dlk5RL5UcgL67vJaDAHRV3k4Q8OiWHHa+G/6OWvUb74iMgVwJruWb1k= X-Received: by 2002:a17:90b:360b:: with SMTP id ml11mr4905738pjb.98.1615992064217; Wed, 17 Mar 2021 07:41:04 -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: Wed, 17 Mar 2021 14:40:52 +0000 Message-ID: To: Peter Stalman Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Fibers From: joshdifabio@gmail.com (Josh Di Fabio) On Wed, Mar 17, 2021 at 9:06 AM Peter Stalman wrote: > > On Tue., Mar. 16, 2021, 23:49 Josh Di Fabio, wrot= e: >> >> Imagine for a moment that you create a library, awesome-library-x, >> which uses a PSR logger internally. You will most certainly allow that >> logger to be injected into your library. Now imagine that some other >> developer uses awesome-library-x in their application, and injects it >> with a monolog logger that logs to some AWS service via the AWS SDK. >> In turn, that logger indirectly uses Guzzle, which adds fiber support. >> As a result, any functions in awesome-library-x which log something >> become asynchronous. Two changes made by two developers unrelated to >> awesome-library-x cause its code to be executed asynchronously. >> >> > Otherwise, if the library uses fibers internally it will have to resol= ve them itself before continuing, no? If `capturePayment()` starts a fiber= then execution will not get to `setTransactionId()`, until it completed or= is handed of to a scheduler (again, which the developer would be aware of. >> > >> > So I don't think developers will face this race condition, unless they= are using framework like amphp and reactphp. But that's already the same = now, so if it's an issue it's not a new one with this RFC. >> >> It is a new issue. Today, interruptible functions must include a >> `yield` statement, so they are explicitly interruptible. > > > No, they don't need to yield. You can do `$guzzleClient->requestAsync()`= today, so how is it different? > > Thanks, > Peter > > Hi Peter, I am referring to functions which can be interrupted or suspended. Guzzle's requestAsync() returns a promise, it does not interrupt/suspend the callsite. For example: // this function is not interrupted/suspended -- it will return synchronously function doSomething() { $this->guzzle->requestAsync(...)->then(... handle response here ...= ); echo "This will be printed before a response is received"; } The following is similar to how one would implement an coroutine in PHP today when using a library which implements a coroutine mechanism, such as amphp. Note the yield statement which interrupts/suspends the function: // this function will be suspended while the request is in flight -- it will return after a response is received function doSomething() $response =3D yield $this->guzzle->requestAsync(...); // do something with response here echo "This will be printed AFTER the response comes back"; } Note the difference between the two. Also note how, in both of the above cases, the asynchronicity is explicit and the developer has opted into it. Both of the above are different approaches to that being proposed in this RFC (this is a design choice by the authors). Cheers