Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108115 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52783 invoked from network); 13 Jan 2020 21:19:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jan 2020 21:19:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A0AC18058E for ; Mon, 13 Jan 2020 11:26:36 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f41.google.com (mail-yw1-f41.google.com [209.85.161.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 13 Jan 2020 11:26:35 -0800 (PST) Received: by mail-yw1-f41.google.com with SMTP id 192so7044757ywy.0 for ; Mon, 13 Jan 2020 11:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=6Zjw8I28Mi2XaxV4uWzUN/mouWH/l9wDlcz33Z6fBFw=; b=WFxWukdeGNE4apU1nEFCXSHLW9qDXaOLjd41PaU718IKdW3/gflu0BiUn3/Hda19su N/eekSBUZbsgDF2rd3Lu85zJfhsTomR5wRlByh6N/HOueWn4suVJkKVGyg+FDCLBghLA T/RBRREs+tbXLsevKvry5T0se8wu+4NMFNQGy48UHhw4yyc5S7OAJEcGOTUMa0rCE4w+ 5NwyLSPma+KHa9Gy8F3F+yh9XDiYakE4AFLfyC6bcaZDoTV7+QNSGYmb2BsU+lB24dgF gl7cW03Epaf+f5ExVnxkLBh/de/24wrgeJ/9NZpC5VacQLMz309FeZJBlrZwaZqOj8vR S++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=6Zjw8I28Mi2XaxV4uWzUN/mouWH/l9wDlcz33Z6fBFw=; b=VJpHcyz75Bk/TW1GfhJin34FEe4BuoxlR0yV5TZ4hgJB+pjAAg67tU5iah/OgYG/kV bJr0yufiocYR2hYwohe3vgr2Es2HN90TI1nE16ej41uqVigj4CMNrmJFL0Ayma7JCJuP 9htfDIFnFMqv9ZpoNB+r/iAh0BinhhHn0k5bouCiSqw6c7h9ma9EPDn0aC7W0kxeipf1 p8rSpwb+unuDC8Uww8Av2tv7VcKIXdKgXddmC3gEFac+okRkAZzRYPo0xl5hzCCLxrE5 a6I9bP+fsBKrHwc1Wdb8xDteJ5F/lAh1FZhOyBVe+0nFQdR0Y0MEbMyNHHDtJzhF1P5W 4cHA== X-Gm-Message-State: APjAAAXTHBhkGNmewKM8uFFWeA0hpypTTWlqhpWy3TlADURj2BkVuRuX TwAXy9YC8/e0fHnKcKit+A9REnyYGptmxQ== X-Google-Smtp-Source: APXvYqwpf6RVTbvLF62umFS/icdTHXJVJeqm+k6pM+KXTHeFD3cdrFM2caf6o7v7i+sG2yNhRjpWkQ== X-Received: by 2002:a25:d081:: with SMTP id h123mr14635664ybg.13.1578943594024; Mon, 13 Jan 2020 11:26:34 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:a059:120f:f626:8488? ([2601:c0:c680:5cc0:a059:120f:f626:8488]) by smtp.gmail.com with ESMTPSA id g5sm5711659ywk.46.2020.01.13.11.26.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jan 2020 11:26:32 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Mon, 13 Jan 2020 14:26:32 -0500 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Larry Garfield X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Introducing compile time code execution to PHP preloading From: mike@newclarity.net (Mike Schinkel) > On Jan 13, 2020, at 1:31 PM, Larry Garfield = wrote: >=20 > On Sun, Jan 12, 2020, at 6:45 PM, Mike Schinkel wrote: >>> On Jan 12, 2020, at 1:57 PM, Larry Garfield = wrote: >>>=20 >>> Most notably, *not all code will be run in a preload context*. =20 >>=20 >> Can you give some concrete examples here? >>=20 >>> Language features that only sometimes work scare me greatly. =20 >>=20 >> Do you have some examples of language features, from PHP or another=20= >> language, that only work sometimes and that are known to be=20 >> problematic. and why they are problematic? >=20 > To use the example from the OP: > > I can see the use of that, sure. Now, what happens when the code is = not preloaded? Does that block not get run, and thus CONST_ARRAY is not = defined? Does it run on all requests if not preloaded? How does that = interact with a file that gets read multiple times? > Thanks so much for going into such detail. It really helped me = understand your concerns. I have been planned to propose an alternate to `static_run` because it = did not seem to me to be an ideal solution. And my proposal would not = have included modifying the AST per se, even though I think that could = be beneficial. Instead it would just be focused on userland preloading = (vs. system admin preloading.) IOW a preload feature that does not require restarting FPM but could = instead be controlled by the userland developer. But before I introduce that I want to better understand why you think = having things that can only run during preload and having things that = can only run during runtime would be a bad thing. To me it seems like a = benefit. Preload vs. runtime are two different contexts. Having = different behavior for different contexts only makes sense IMO. Look at = CLI vs. FPM contexts: - https://stackoverflow.com/a/25653068/102699 I get your concern about recursion, but if that kind of issue is really = a concern I don't see why we could not artificially limit recursion on = preload to a configurable amount, with 100 being the default? Again, if we can I hope we can focus on concrete problems this would = cause that we might be able to solve vs limiting to only abstract = concerns. -------------- Separately I think it would make sense to provide a set of APIs to do = the most commonly needed things that people might want to modify the AST = for. One example that I could envision that would make sense for preload but = probably not for runtime is an extension of the Reflection API that = would allow code to define classes, interfaces, traits, functions, etc. = Here is something I mocked up that I called "Projection" to illustrate = that concept: - https://gist.github.com/mikeschinkel/e07eb14a34ce83a96198744e18b0c961 -------------- I do completely see your points about the AST and most PHP developers. =20= The unfortunate problem with PHP is there is no way to use 3rd party = code to extend PHP w/o being able to reconfigure the server by adding = extensions. It would be nice if we could come up with a way for 3rd = party developers writing in C or another language =E2=80=94 people who = are more likely to test their code before distributing it =E2=80=94 to = extend PHP such as by generating OpCode files that a userland developer = could load. =20 Or maybe we implement ability to load Web Assembly on the server? If = that were possible I could write PHP extensions in Go. :-) I think these discussions should be on a different thread though. I = think we have 3 different topics here: - Userland preloading - Projection API and related - Userland loadable extensions -Mike