Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108125 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32053 invoked from network); 14 Jan 2020 20:04:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jan 2020 20:04:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 091CB18056A for ; Tue, 14 Jan 2020 10:11:04 -0800 (PST) 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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 ; Tue, 14 Jan 2020 10:11:03 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id D112221C7D for ; Tue, 14 Jan 2020 13:11:02 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 14 Jan 2020 13:11:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=/DTpt+dTVOzkLeyoHoMso3Qbgzscf4xeCihtHVZg1 7A=; b=KY3L0ec3bN++re671vm9Vs1PlsoyTZo7/n7KphWRJPhYgTH90HnvaFdRn r1K5STBg56unsEBN9hjafOYvEgaiE5KIz/BMG3aAS+UFPjY22Cncz+HodsAh9Rmr 3kuBemY8TT335FSVw50So2rIpGJ6M/D8nrtZQzVkE7Mrwk8T5EINmM+7VC2c8okM xEoiBBL6NUbftA86wzVRFHUlTHRSO0zeXj7e21OYJAP866V55N3dCR+mdziWQ8lL D7GfDBdg8Zy2VboUW5B1XNEceFjDo2Zt+dgLvbAOJela4viiSHc8KLFxUxbEWpIG eFNJUr1PQ2BnUEhlCLNrh1Z4eH7Rw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddugdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucffohhmrghinhepshhtrggtkhhovhgvrhhflhhofidrtghomhdpghhithhhuhgs rdgtohhmnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlug htvggthhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9075C14200A2; Tue, 14 Jan 2020 13:11:02 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-754-g09d1619-fmstable-20200113v1 Mime-Version: 1.0 Message-ID: <2502e68d-a1bc-41c6-9763-8c0e2ac9e6f4@www.fastmail.com> In-Reply-To: References: Date: Tue, 14 Jan 2020 12:10:41 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Introducing_compile_time_code_execution_to_PHP_p?= =?UTF-8?Q?reloading?= From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jan 13, 2020, at 1:26 PM, Mike Schinkel wrote: > Thanks so much for going into such detail. It really helped me=20 > understand your concerns. >=20 > I have been planned to propose an alternate to `static_run` because it= =20 > did not seem to me to be an ideal solution. And my proposal would not= =20 > have included modifying the AST per se, even though I think that could= =20 > be beneficial. Instead it would just be focused on userland preloading= =20 > (vs. system admin preloading.) > IOW a preload feature that does not require restarting FPM but could=20= > instead be controlled by the userland developer. I defer to Dmitry on whether such a thing is reasonable. My engine know= ledge is far too paltry to comment. > But before I introduce that I want to better understand why you think=20= > having things that can only run during preload and having things that=20= > can only run during runtime would be a bad thing. To me it seems like= =20 > a benefit. Preload vs. runtime are two different contexts. Having=20= > different behavior for different contexts only makes sense IMO. Look=20= > at CLI vs. FPM contexts: >=20 > - https://stackoverflow.com/a/25653068/102699 That's slightly different, as code will still execute in both contexts. = And most of those differences are related to how PHP interacts with the= outside world, in two different definitions of "outside world". To illustrate my point, though... Well, that explains why my last attemp= t to use STDOUT and STDERR in a non-CLI context failed without explanati= on! TIL... > I get your concern about recursion, but if that kind of issue is reall= y=20 > a concern I don't see why we could not artificially limit recursion on= =20 > preload to a configurable amount, with 100 being the default? It's not recursion itself that's an issue. It's that the behavior of th= e code changes between preload and non-preload contexts in subtle, non-o= bvious ways. I don't mean a recursive function that runs during preload. I mean if a= function that runs in a normal request is written recursively, it will = fail at high recursion levels only if the file it is in was not preloade= d. So whether or not foo.php was run through opcache_compile_file() cha= nges when and how code in that file will fail. That's the situation we = want to avoid like the plague, IMO. > Separately I think it would make sense to provide a set of APIs to do=20= > the most commonly needed things that people might want to modify the=20= > AST for. >=20 > One example that I could envision that would make sense for preload bu= t=20 > probably not for runtime is an extension of the Reflection API that=20= > would allow code to define classes, interfaces, traits, functions, etc= .=20 > Here is something I mocked up that I called "Projection" to illustrate= =20 > that concept: >=20 > - https://gist.github.com/mikeschinkel/e07eb14a34ce83a96198744e18b0c96= 1 I've seen similar concepts for code-generation libraries. I've even wri= tten a very basic one at one point. That seems orthogonal to whether th= e end result is writing the generated code to disk or compiling it direc= tly into memory. If we do make runtime code generation a first class ci= tizen then some sort of API like that would be a good idea (as the alter= native is to build a string and run eval()). > -------------- >=20 > I do completely see your points about the AST and most PHP developers.= =20 >=20 > The unfortunate problem with PHP is there is no way to use 3rd party=20= > code to extend PHP w/o being able to reconfigure the server by adding=20= > extensions. It would be nice if we could come up with a way for 3rd=20= > party developers writing in C or another language =E2=80=94 people who= are more=20 > likely to test their code before distributing it =E2=80=94 to extend P= HP such=20 > as by generating OpCode files that a userland developer could load. =20= That... sounds a lot like the new FFI extension? Write code in C or Rus= t or anything that can produce a .so file, plug it into PHP, go? There's a whole lot of caveats on that, of course. I'm working on a blo= g post series on that very topic at work, so stay tuned if you're intere= sted... :-) --Larry Garfield