Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122029 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12497 invoked from network); 24 Dec 2023 15:21:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Dec 2023 15:21:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E6256180052 for ; Sun, 24 Dec 2023 07:21:51 -0800 (PST) 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 ; Sun, 24 Dec 2023 07:21:51 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9722A5C006B for ; Sun, 24 Dec 2023 10:21:26 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sun, 24 Dec 2023 10:21:26 -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=fm2; t=1703431286; x=1703517686; bh=PnkPb2PJTwjN2unVvQbc5 q65oQ6/wJry3K2a0BxxrmE=; b=IZ5qO7bPXP6QMuMoiR7D5zkHl7FEABszDO1t6 ZtUrpsKwPFkG8NI0qA5zXHsnRcrWKeisiTNDj2NDe/E8bpGJAUGfDEGKJ2eRdWby /dG0AOgeeu2yy52B1xlY1OynJvq00s/fF9l1/IoR+SFQdfSp3WhPhPYeGAG8LMmK KIvG8ycfFUsosmrH1v5QXdoSRhTsQ7ytvReUYwmOG2MmQvUuJApwj3+5Tt/LUity L0cGJbOxwv4AgWQuhtvOqXPD8HgqNCBEQVD2wCiVYzphe1rzJgyI7Pas9N3iDSA3 z1Jxmeo580E0l7GqlanigqkVvgrIPkCtwPV7eH0L5RFyxLfFw== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1703431286; x= 1703517686; bh=PnkPb2PJTwjN2unVvQbc5q65oQ6/wJry3K2a0BxxrmE=; b=K gmfQxxGiGYytbZLEkKX7pxJ6eJ+Yy0Zmw6HMN91AJuWlBacyVCmoiJ1/JrQAk9xH lcmA1fi8CRoGZWu/+OGkZ88Md4oBPohAfiIVA0KgcO/cVCISpmv8Q4AHSgeY/ASX +U2yVyB5BPYerwOzln5vmPO62FjBrta5FMGV6qr2BY6zTIXxZXtNAhIEe7qGlkFA ybSBgFNMmE2AY2x98sXOroCZkyrPJE3CdXmGA/hoZYlPEK8kDBYdWkSGOAlrxJNd BD4x/YJKI5l+ZTJ9HyW8REim78GAaf3gecd2rborIvTUQnNL3+B3txY5FUD/3c13 a5nxkiP+Gribjc6ngM/eA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddvuddgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepkedvudejjefhheefffetueeggfelgfejueevgedu udejtedtteevuefgudekgedtnecuffhomhgrihhnpehgihhthhhusgdrtghomhdpfhhrrg hnkhgvnhhphhhprdguvghvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 39A131700093; Sun, 24 Dec 2023 10:21:26 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1364-ga51d5fd3b7-fm-20231219.001-ga51d5fd3 MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Sun, 24 Dec 2023 09:21:05 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 23, 2023, at 2:34 PM, K=C3=A9vin Dunglas wrote: > Hello and Merry Christmas! > > One of the main features of FrankenPHP is its worker mode, which lets = you > keep a PHP application in memory to handle multiple HTTP requests. > > Worker modes are becoming increasingly popular in the PHP world. Symfo= ny > (Runtime Component), Laravel (Octane), and many projects based on these > frameworks (API Platform, Sulu...) now support a worker mode. > > In addition to FrankenPHP, projects such as RoadRunner and Swoole prov= ide > engines supporting worker modes. > > According to benchmarks, worker modes can improve the performance of P= HP > applications by up to 15 times. > In addition to FrankenPHP, which is basically a SAPI for Go's integrat= ed > web server, a new generation of SAPIs is currently under development. > Several SAPIs written in Rust (including one by the RoadRunner team) a= re > currently under development. > > These SAPIs, along with existing SAPIs, could benefit from a shared > infrastructure to build worker modes. > > > > The FrankenPHP code is written and should be easy to move around in PHP > itself, to enable other SAPIs to use it. > > In addition to sharing code, maintenance, performance optimization, et= c., > the existence of a common infrastructure would standardize the way wor= ker > scripts are created and provide a high-level PHP API for writing worker > scripts that work with all SAPIs that rely on this new feature. > > SAPIs will still have to handle fetching requests from the web server = and > pausing the worker to wait for new requests (in FrankenPHP, we use > GoRoutines for this, in Rust or C, other primitives will have to be us= ed), > but almost everything else could be shared. > > For reference, here's the FrankenPHP code I propose to integrate into > libphp: https://github.com/dunglas/frankenphp/blob/main/frankenphp.c#L= 245 > > The public API is documented here: > https://frankenphp.dev/docs/worker/#custom-apps > > I'd like to hear what the community thinks about this. Would you be > interested in this functionality in PHP? Should I work on an RFC? > > If there's interest, I can work on a patch. > > Cheers, In concept, I love this and would be ecstatic to see it happen. In practice, I want to understand the implications for user-space code. = Does this mean FPM could be configured in a way to execute a file like = that shown in the docs page above? Or would it only work with third par= ty SAPIs like FrankenPHP? I assume the handler function would be differ= ently named. Is passing in super-globals the right/best way to handle e= ach request, or would it be sensible to have some other abstraction ther= e? (Whether a formal request object a la PSR-7 or something else.) To = what extent would user-space code run this way have to think about concu= rrency, shared memory, persistent SQL connections, etc? Does it have an= y implications for fiber-using async code? Depending on the details, this could be like fibers but for 3rd party SA= PIs (something about 4 people in the world actually care about directly,= everyone else just uses Revolt, Amp, or React, but mostly it doesn't ge= t used), or completely changing the way 90% of the market runs PHP, whic= h means frameworks will likely adapt to use that model primarily or excl= usively (ie, less of a need for a "compile" step as a generated containe= r or dispatcher is just held in memory automatically already). The latt= er sounds exciting to me, but I'm not sure which is your intent, so I do= n't know if I'm going too far with it. :-) Please advise on what the implications would be for the non-SAPI-develop= ing PHP devs out there. --Larry Garfield