Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126584 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 9A5A21A00BC for ; Wed, 5 Mar 2025 18:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741199771; bh=9f4t0ddGbZOY1I6TGiMcRXUu5mSfkC4wRXTzQiTEKTI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=EEFmVB8UHcjNgXfo0HpwRTSsT+Uy/qnVU3m9j+Bl0g8lAAn+RjtC/EYYcoYy5grKC wlhVxqpQpXvy+zlX57KaAr+EdDe/xI8GIko4yQLsW9+bfagBB23Z+Or94EEP8FbbZx 4RuzQPq62qSM8+Thysd4ihF0s/NqQwQjT2Ti2AufmS1jZqE4c+IfLPmr+um1Bvkn6K rzWQho2YSdRNU8jz2vS98sjREIVnCQ+TFnwh1tsiyQ5AP3GyhuYJFNpmiL7AVxI8Un cQAOuaz9aefblj3fX/Xp9Nwzo5+l1EZaiUr+w1vLT5ozvGRspooE5v1mG125JmOMuT OQcem7ABG61jA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD3DE180068 for ; Wed, 5 Mar 2025 18:36:10 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Wed, 5 Mar 2025 18:36:10 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2410925401B4 for ; Wed, 5 Mar 2025 13:38:46 -0500 (EST) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-04.internal (MEProxy); Wed, 05 Mar 2025 13:38:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1741199925; x=1741286325; bh=9D9JfTXS6x5Yv+Kw3uKqC 53982ggmnd2HESTLQ+sPUc=; b=Sj/RTtSNxfy+V9uJX6tQLLNYqR7RaAmPDM1di v30Dy2CJzqPRymK4Sz+G0rK6V2xXSbo2FzbAdmS7E/RFFF6TEQyNsXIsvgu2zigr FR8S1SOVtWFfWh6ppMuluNpsF5mOvdkv9ec9+ytKELE93/jYO31dF8ayg6O4z6sm 3X6puxYu8JSIyp9c5SUUbIvJjSvtpsKHxK+gjEMvBtPZN891K9grlXGpiFMwci57 ToT119jnxB7C1VA+es6r+p/bU+/NfFpX1m8+9fS70iO4fSt18M5HYV5b9h6fGV8J cmrUahTlNvhNuJOj3EtKRvVzkWjewt9dvXR0tQWhsww+ScHUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1741199925; x=1741286325; bh=9 D9JfTXS6x5Yv+Kw3uKqC53982ggmnd2HESTLQ+sPUc=; b=KQIC3halR0hBslu2O 7ZfgT2WWlbaDz8ScnN/bbMhzSTtnVaQDtDTylqWn0ly+kHpkh9iLVcnmuSJu6Khw gffyYGT6kKpOBvD4Wk3IhmvCNEzc//p0J/Rg83yFJPt2majY0sbohGerzWHCPcYN PBIjGj1VgV0dLc2a0QcKd8NVyOxX7SpfiH+VVtOF19qUGLGhBfM63D6WXMZNixvv nZTXkNsNi/0mfqDixlsQC1PL6x5TCNiA0yhheUmrvO69rkIpMxNRewZSboUP1ixm vuoAQ3jkWGS3ajIDApQPFIUntiHR6FtOPtQI+3JNNSigj9oLu7817mFzHcwUyRWD Houyw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdehheekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthejredtredt tdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeeuvedvudfhffffhfel ueehvdejvefgleegteegffetudefleehgeefvdehgeelteenucffohhmrghinhepphhhph drnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtohepud dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishht shdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id AC44D29C006F; Wed, 5 Mar 2025 13:38:45 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 05 Mar 2025 12:38:24 -0600 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] PHP True Async RFC Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 5, 2025, at 11:50 AM, Edmond Dantes wrote: >> You might want to look to parallel extension as it's already dealing >> with that and mostly works - of course combination with coroutines will certainly complicate it but the point is that memory is not shared. > > Do you mean this extension: https://www.php.net/manual/en/book.parallel.php? > > Yes, I studied it before starting the development of True Async. My > very first goal was to enable, if not coroutine execution across > threads, then at least interaction, because the same thing is already > possible with Swoole. *snip* > Such a language update would create an "extension vacuum." When a new > version is released, many extensions will become unavailable due to the > need to adapt to the new multitasking model. It would necessitate a major version release, certainly. >> I didn't really mean to introduce it as part of this RFC. >> What I meant is to design the API so there is still possibility to add it in the future without risking various race condition in the code. >> It means primarily to put certain restrictions that will prevent it like limited access to global and passing anything by >> reference (including objects) to the running tasks. > > Primitives like *Context* are unlikely to be the main issue for > multitasking. The main problem will be the code that has been developed > for many years with single-threaded execution in mind. This is another > factor that raises doubts about the rationale for introducing real > multitasking in PHP. I think the point is more that the concurrency primitives that are introduced (async block, async() function, whatever it is) should be designed in such a way that PHP could introduce multiple parallel threads in the future to run multiple async blocks simultaneously... without any impact on the *user* code. To reuse my earlier example: function parallel_map(iterable $it, Closure $fn) { $result = []; async $ctx { foreach ($it as $k => $v) { $result[$k] = $ctx->run($fn($v)); } } return $result; } Whether each run() invocation is handled by one thread switching between them or 3 threads switching between them is not something the above code should care about. Which means designing that API in such a way that I... don't need to care. Which probably means something like "no inter-fiber communication other than channels", as in Go. And thinking through what it means for the context object if it does have some kind of global property bag. (This is one reason I don't want one.) And it means there's no way to control threads directly from user-space. You just get async blocks, and that's it. This is an area that Go got pretty solidly right, and is worth emulating. The implications on C code of adding true-thread support in the future is a separate question; the async API should be built such that it *can* be a separate future question. --Larry Garfield