Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118870 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7931 invoked from network); 23 Oct 2022 13:57:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Oct 2022 13:57:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DFDFA180041 for ; Sun, 23 Oct 2022 06:57:44 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS17378 206.123.64.0/18 X-Spam-Virus: No X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 23 Oct 2022 06:57:44 -0700 (PDT) Received: from smtpclient.apple (unknown [49.48.243.6]) by mail1.25mail.st (Postfix) with ESMTPSA id 3484660402; Sun, 23 Oct 2022 13:57:36 +0000 (UTC) Message-ID: <6C17C72E-05D9-4543-B6FB-D86B4C14A2AE@koalephant.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_3423BD56-3EC7-4BB9-9631-52B302B1D239" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Date: Sun, 23 Oct 2022 20:57:33 +0700 In-Reply-To: <50321070-3682-c238-d8b4-3d0f6832c4bc@pouzenc.fr> Cc: internals@lists.php.net To: Ludovic Pouzenc References: <50321070-3682-c238-d8b4-3d0f6832c4bc@pouzenc.fr> X-Mailer: Apple Mail (2.3696.120.41.1.1) Subject: Re: [PHP-DEV] Newcomer, PHP pre-processing, Magic Constants __FILE__ and __LINE__ override with #line like in C From: php-lists@koalephant.com (Stephen Reay) --Apple-Mail=_3423BD56-3EC7-4BB9-9631-52B302B1D239 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 23 Oct 2022, at 20:43, Ludovic Pouzenc wrote: >=20 > Hi, >=20 > I'm a newcomer here. I came from https://wiki.php.net/rfc/howto. >=20 > *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. >=20 > 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. >=20 > *Background / use case:* I think at first about webservices, maybe the = useful also with browser/human-facing use cases. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > In my university, I started using a purpose-written PHP Preprocessor = to minimize runtime dependency loading. It only understands #include = like in C. =46rom 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. >=20 > 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. >=20 > 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. >=20 > 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) >=20 > I hope it could unlock many use cases where "big" PHP frameworks get = really hard time to try to compete with other languages equivalents. >=20 > Do you think it's an idea that is suitable to discuss, improve and = submit as an RFC ? >=20 > Regards, >=20 > --=20 >=20 > Ludovic Pouzenc > www.pouzenc.fr >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >=20 Hi Ludovic, I can=E2=80=99t comment much on the actual change in the parser you=E2=80=99= re asking about, but it sounds to me like preloading = (https://www.php.net/manual/en/opcache.preloading.php = , introduced via = https://wiki.php.net/rfc/preload ) = might be a workable solution that=E2=80=99s already available? Cheers Stephen=20= --Apple-Mail=_3423BD56-3EC7-4BB9-9631-52B302B1D239--