Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113604 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74589 invoked from network); 18 Mar 2021 16:09:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Mar 2021 16:09:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C4CF81804F6 for ; Thu, 18 Mar 2021 09:03:39 -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-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 ; Thu, 18 Mar 2021 09:03:39 -0700 (PDT) Received: by mail-pj1-f44.google.com with SMTP id bt4so3156480pjb.5 for ; Thu, 18 Mar 2021 09:03:39 -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; bh=lkj8BfGzIYy2gTttGplDLHNyZ2PA2MLzJsWykD5E+wM=; b=sr6u5U4PyuCD5Yix9aNQV0UXzdz1fOSC346GVwfkp8oOGTYPdPLY4M1sR59HsTufRZ JragCVLvENjMWhhx+VCDSxFonwTjbL7btGT41pBBt8eqvRdr0u8ltgi/xWlGpRBjgMj2 j4RVl8QLMyV0knfxk52xfu84yLCQjL86lHADNvzV4YLIowa1ZYB66BBxQ+62PYlAqnm3 FB1CzPNbZ3/3qNChkS0Ohk7e1UezKsxWz7IfwL6P7WLKjAVKSjbjoMvbqcdSY+ecpXqU 1tXcYPjS0G/qRpe3tebi+5TsZllTAaEW3VuAI7JFuIR/NjtnlY7PD/qXTCL3rZg4tqeR otUA== 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; bh=lkj8BfGzIYy2gTttGplDLHNyZ2PA2MLzJsWykD5E+wM=; b=TQpv5wbUCnPjZTrX9qoqNIVktDHNjKsyaFh16FTWaLFrrEAvznxdwBNQki3Bx3xM6V cXkzU3B0ZHqkEgztJ/x2wt21cCuAW4RWh9VFjJ3HzY7iwWLl27Y6dIEgI10uxhe0oUcN qiILi8FPVKMah5nFFEP1ntB2quWUwNAV5bAlxDGrKBu5VQ7rH/rn3iPvvCH6fbs9dYNK r69khSSqK1yQ0+qc195WSM/8DwrrODlBNIqmWtDgfIRQUVKN2f5vDPLq4CbSlwuv93M3 vLo0cTfOZKJw8VbexisGyPOar2TYHrtDvnFz5gKcijvnWxUzaqoC+wp7ko8Recg/WOMd NhqA== X-Gm-Message-State: AOAM530GHaDPW4oS/EDThaA9TQTxaZvRJ2BI8eogq2eo0CdGISXsHzmt ru6GAGDHE1h1R1sZnMaUNdKRO1M5A8rVebH2xAs= X-Google-Smtp-Source: ABdhPJz1cGQHmTMCsNUZsQVTNb6ujn2uEGPFAy7oArrE31Ibqx6txCwpd4ssQZARSaZG8o/aw2G0iqzQ3BFzx4fXXbE= X-Received: by 2002:a17:902:dcd4:b029:e6:5398:609f with SMTP id t20-20020a170902dcd4b02900e65398609fmr10174259pll.58.1616083416605; Thu, 18 Mar 2021 09:03:36 -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: Thu, 18 Mar 2021 16:03:25 +0000 Message-ID: To: Guilliam Xavier Cc: Peter Stalman , php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] Fibers From: joshdifabio@gmail.com (Josh Di Fabio) On Thu, Mar 18, 2021 at 1:55 PM Guilliam Xavier wrote: > > Hi, > >> 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 = 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). > > > At the risk of sounding dumb: What would that code look like with fibers? > > Thanks, > > -- > Guilliam Xavier Hi Guilliam, With fibers, a non-blocking call to Guzzle would look exactly the same as a blocking call. function doSomething() $response = $this->guzzle->request(...); // do something with response here echo "This will always be printed AFTER the response comes back"; } Whether request() and therefore (doSomething()) blocks the whole process or merely suspends the current fiber would depend on whether or not doSomething() was called within a fiber, and whether Guzzle had fiber support, which would be defined elsewhere. Cheers