Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126431 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A39561A00BC for ; Mon, 17 Feb 2025 17:29:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739813226; bh=DtunzvbLNgnBG7SqOS5Lxy44Jb8bWrRb7pVXwM52Ybw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VmP/SCA9wGG7gKW0kKcXTkCl49OR1ECtoWJAt3mUvGEZqKx8nSkrqzYqSHKNjpyBt xMf8I8bCOrA9GTuRR4x6Lvmegk3oCgaWlCO0TftKl/X4B2l3yZ4AtdQFfdgw7YhmEt 5DgPNy8pqEujmUYDlrwkonOx94IqajJXgICzZoc5/vlk9jQ1FPxdQwCjUW3cCZf0Jy U6ClPaaWbcDOJdJrttoMMuiubopF+cIHflEkck6IMPPpMdXsKLrfryKHGOTkK8mvKv 0yX51kOJotw2+BotX0zxvfvYWqqAZhCLnyFIFGip1X9ESp7kMGS87YdfnD5L2yTYDP jsMTGc8vIR4Lw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5FA80180086 for ; Mon, 17 Feb 2025 17:27:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Feb 2025 17:27:05 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e5dc37f1991so2315040276.2 for ; Mon, 17 Feb 2025 09:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739813386; x=1740418186; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DtunzvbLNgnBG7SqOS5Lxy44Jb8bWrRb7pVXwM52Ybw=; b=SmGivbO/oO7pWMHltKyBvSAaEU5MCupOL6ch0R3Rt2y0z+qybsKnSiJAaAbLKUeBGg v3VX0pkyHCrABBgUJtStt5ZEW0sviZv/v9qRDQGuZQw4ZtEeyaYlwE2GOWZTFDo7ALnO 2fm4pWDY7H8kNHsSy5DnoPxIQDSf5tEdzNBiBGftrC9gY4UJHlsXIvBGdqSZJS52tnmx CfTh1pmonv3PKHPgLp9f0QpBkG3IM/dDzTiFN6nuzZ6m3ndgxcn9vDvWErsLHcvJBNtd kWiMehfKzw+fRds+3LDOnETVi47+H6i5Su1ZdWt2uORejSw2hgMH2kKOkAVMN9PhAhva 1DuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739813386; x=1740418186; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DtunzvbLNgnBG7SqOS5Lxy44Jb8bWrRb7pVXwM52Ybw=; b=ix8Mywu2c/zEXAJ337Kec2Dr0bLrnnTko9KwbOZAYJGk9EfrFoJf00KXIatvvccuO1 NKwJHC+ZbLtprsBa65o5yUyjaMkDqM6QKrZ9MTzEWoah6+au1cplqaKMJfm/ks0MPhEf 2TmVVUTcLoo1FpdTDkq5VQUZ5v2GZyOFegP4FxG3VUWVglvqxCZP1iq/kr3w8mBysEAZ CkJgbarFWDzHQWVDxZDOS6NdVHJX2LAVzuxYBLDvygvBlBpsjdoNTc/2ncGFa6Am4b5e 2x8c/3aTNvgmohBPl/iJfzOdc4nIXJGe4ZQdOvABMxpZwKgwqB8DbOpV7xSIDDrOorF9 q9jA== X-Gm-Message-State: AOJu0YwAyQrwl+PgFG6TVoGuzLUkLjieyeD8vbY5FUOKHLKVby7J9P/7 HQXeMQGMttn+pBfW8/iRLZ6YU6KYXS9q5em4oPWR8hKfyS8hG+iJii4Z7Rky5k4tuYg11uM0/3q amrdZb6CyTHf/1SEUHjKTwSuHuhE= X-Gm-Gg: ASbGncsCWCDVFaenobZxb+Y7qiQtERpO7WCv1bT8nh3+cEfzBrMOu8YAY8eHavcbuJV 1bkqOoc54pkfZZxeIsxIKxCfFnr33RCf/TFiPcG44OfRCYtUzIXSjn8S5LRsjSmjwWrzkWBvg X-Google-Smtp-Source: AGHT+IGOm44OL/i0wMmJh2CjkAQFRB5zwd79YNXqsuuZSoK5Wf/qi/MH27DIyzWzUMgfJqe5qXK6dmAzck52piZavbQ= X-Received: by 2002:a05:6902:2104:b0:e5d:929e:6311 with SMTP id 3f1490d57ef6-e5dc91ee6afmr6425562276.36.1739813385795; Mon, 17 Feb 2025 09:29:45 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <24becc76-b67f-4805-b33b-cd4f9f6d0b30@scriptfusion.com> In-Reply-To: <24becc76-b67f-4805-b33b-cd4f9f6d0b30@scriptfusion.com> Date: Mon, 17 Feb 2025 19:29:34 +0200 X-Gm-Features: AWEUYZk_WcXNrtrOM75ccL0ZHe03MCjA6inPG0eRUoUL-Bh68vwenipLg47zHmw Message-ID: Subject: Re: [PHP-DEV] PHP True Async To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000d60838062e59de80" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000d60838062e59de80 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Bilge! > Is it really necessary to have all these `Async\launchScheduler();` calls? Why can't the scheduler always be running, the same as it is in JavaScript or any other async language? Even (userland) Revolt does not require the event loop to be manually started. *Short answer:* This implementation is simpler =E2=80=94 not so much in ter= ms of code size but in terms of reducing =D1=81onfusion. And we achieve a consist= ent state when asynchronous code runs within a Fiber, rather than having a situation where we are in a Fiber here but not there. For example, consider how the Fiber switching mechanism works in PHP. If FiberB is launched from FiberA, FiberB can only return to FiberA. Consequently, if the Scheduler component is placed inside a Fiber, the code must track the "direction" of switching. Running the Scheduler in the "zero" Fiber results in the simplest possible switching logic. It also defines a clear point where exceptions can be thrown. One might argue that no other language does it this way. But then, no other language has Fiber as a low-level tool (except C). From this perspective, explicit activation of the Scheduler aligns with Fiber as a low-level construct. Can this be avoided? Yes, but such alternative approaches often rely on *implicit behavior*. And implicit behavior tends to break things. Of course, we could start the code inside a Fiber to initialize the Scheduler and hide the implementation, but again, that's not always necessary or useful for everyone. Ed. --000000000000d60838062e59de80 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Bilge!

> Is it really necessar= y to have all these `Async\launchScheduler();` calls? Why can't the sch= eduler always be running, the same as it is in JavaScript or any other asyn= c language? Even (userland) Revolt does not require the event loop to be ma= nually started.

Short ans= wer: This implementation is simpler =E2=80=94 not so much in terms= of code size but in terms of reducing=20 =D1=81onfusion. And we achieve a consistent state when asynchronous code ru= ns within a Fiber, rather than having a situation where we are in a Fiber h= ere but not there.

For example, consider how the Fiber switching mechanism works= in PHP. If FiberB is launched from FiberA, FiberB can only return to Fiber= A. Consequently, if the Scheduler component is placed inside a Fiber, the c= ode must track the "direction" of switching.

Running the Sc= heduler in the "zero" Fiber results in the simplest possible swit= ching logic. It also defines a clear point where exceptions can be thrown.<= /p>

One might argue that no other language does it this way. But then, no= other language has Fiber as a low-level tool (except C). From this perspec= tive, explicit activation of the Scheduler aligns with Fiber as a low-level= construct.

Can this be avoided? Yes, but such alternative approaches= often rely on implicit behavior. And implicit behavior tends to bre= ak things.

Of course, we could start the code inside a Fiber to initi= alize the Scheduler and hide the implementation, but again, that's not = always necessary or useful for everyone.

Ed.

--000000000000d60838062e59de80--