Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118871 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14070 invoked from network); 23 Oct 2022 16:02:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2022 16:02:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 58D51180044 for ; Sun, 23 Oct 2022 09:02:25 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 23 Oct 2022 09:02:24 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 29ED55C0094 for ; Sun, 23 Oct 2022 12:02:22 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sun, 23 Oct 2022 12:02:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1666540942; x= 1666627342; bh=pczhZc/y2d3G4Qq9rze/+Wd1PG4RIACEe0czqi6vxkM=; b=S JGusqBLpiIfLrdsNAfSxq4lEFe/GFjhvLt8df4tjoPIMmvaOqsX5NjeyaEjExvHJ 8LSzR1poeAkezR5ve7F/tSafyYq8nw8n3VxIyKFUv7LhUYPzYvOz3Jb1/jwYoAPi E/W/CZcfpBnDqA0XTrfJzSoeJD4djgEJo0gTKV49ReQkyRyE/fCM8B+VS02VCXRI xh6S9nGh6IpVX2wuxUxN34pahiZajc2j1oLPQCDc4SXTedz++GACacnCfB3yp4AG bHIGaaSeB3mBtUMA9zDV0a9rxfZ9fMF/6d48Alac84m8ionQIUOUAeqUWXinFJqS guhhoa/AmqQkzSaUAIeCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1666540942; x=1666627342; bh=pczhZc/y2d3G4Qq9rze/+Wd1PG4R IACEe0czqi6vxkM=; b=UHScDh5LzMj2lPB70bEpbNasSDCeQrKbIzmugO2qxsnv elhJVuQ0TrLic1WKZmeHSdNny/Bxzfw/PUc6xBa6NvcYxnVrC0CUlesNafdhgNs9 F0XmvIjr8/yHK9CoqAsqZ8s8FvPDyU9Xuqmr34PiAr4q/Yt3YQUb5YbZQcCAnDD5 n1akZl2yPSrMvBvzTxawtxsj6Sj8fHkbTkRI8Ug6d2OSdDfasnwtyw9saoeTdPtU 78evVWP+m2/p8Zb9GhEnQeuK4EF+UQljEod3LfyfbsSFSTP7FpkPNBayixNPzkL9 njrVgAj77o2HjD6nTIsxGL2oNNq46IElDRc/vF+zZg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrgedtvddgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeevheehvdevjeelvdevgfelvefftdejkeelvdekgeeh fffgiedvjefhhfeltdduteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhi vghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D831C1700083; Sun, 23 Oct 2022 12:02:21 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1047-g9e4af4ada4-fm-20221005.001-g9e4af4ad Mime-Version: 1.0 Message-ID: In-Reply-To: <50321070-3682-c238-d8b4-3d0f6832c4bc@pouzenc.fr> References: <50321070-3682-c238-d8b4-3d0f6832c4bc@pouzenc.fr> Date: Sun, 23 Oct 2022 11:02:01 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Newcomer, PHP pre-processing, Magic Constants __FILE__ and __LINE__ override with #line like in C From: larry@garfieldtech.com ("Larry Garfield") On Sun, Oct 23, 2022, at 8:43 AM, Ludovic Pouzenc wrote: > Hi, > > I'm a newcomer here. I came from https://wiki.php.net/rfc/howto. > > *TL;DR:* I want to know if a proposal of a #line parsing to alter > __FILE__ and __LINE__ in PHP like it exists in C could be a good idea. > > I've searched about __LINE__ and __FILE__ in mailing archives and wiki, > I don't really find things matching. I hope it's not because "__" are > stripped before search. "Magic constants" didn't help neither. Let me > know if I am rethinking and old thing already imagined here in the past. > > *Background / use case:* I think at first about webservices, maybe the > useful also with browser/human-facing use cases. > > With PHP, it's hard to get high responsiveness under load if user code > start by loading a composer's autoload.php, then (lazy) loads a whole > framework with 10+ dependencies, then execute 1 SQL request, 1 > json_encode() then output and exit. Even with "Slim" framework that > should be minimal, using only the route feature, I see "strace" counting > 200+ file-related syscalls per request with recent > linux/debian/apache/php-fpm. > > It's not so hard to get it better with other langages : when they are > compiled, or when framework loading happens at server start and to at > each request. > > Web projects have more and more a "compilation" phase for minimising JS, > for proprocessing scss to css, it is possible to hook it some PHP > processing too. > > In my university, I started using a purpose-written PHP Preprocessor to > minimize runtime dependency loading. It only understands #include like > in C. From a src/mywebservice/v1/some-endpoint.php it will generate and > build/mywebservice/v1/some-endpoint.php with all #include > "some/path/somedep.php" replaced by the file's contents. > > So the generated some-endpoint.php have no run-time dependency at all: > no autoload, no include(), no require(). I think it evens maximize the > gains with APC caching. > > The preprocessor also generate things like #line 2 > "some/path/somedep.php" where an #include was encountered, then a thing > like #line 47 "src/mywebservice/v1/some-endpoint.php" right after the > end of the inclusion. In C, a great concrete example of #line importance > is working with a flex/bison parser generator. > > If PHP parser interpret #line as in C, __FILE__ and __LINE__ Magic > Constants will be changed to source file and line, instead of generated > file and line. It could greatly improve development write-then-rerun > cycle. (missing ";" at line NN , other PHP Errors, Exception details/traces) > > I hope it could unlock many use cases where "big" PHP frameworks get > really hard time to try to compete with other languages equivalents. > > Do you think it's an idea that is suitable to discuss, improve and > submit as an RFC ? > > Regards, It sounds like there are numerous existing approaches to address the situation you describe that are already in use and far more effective than making constants stealthily dynamic. 1. Opcache preloading, introduced in PHP 7.4. 2. Disable the stat calls on opcache, so it doesn't even check the disk at all once something is in cache. 3. Use a persistent-process tool like React PHP, AmPHP, Revolt, and the like, so it functions more like Node.js instead of using PHP-FPM. I think you're also greatly over-estimating how large the startup cost is in practice. It's real, certainly, but unless you have several nested microservices a well-made framework should have a fairly small overhead. --Larry Garfield