Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108128 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49041 invoked from network); 14 Jan 2020 21:15:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jan 2020 21:15:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 44F8B180569 for ; Tue, 14 Jan 2020 11:22:42 -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-f54.google.com (mail-yw1-f54.google.com [209.85.161.54]) (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 ; Tue, 14 Jan 2020 11:22:41 -0800 (PST) Received: by mail-yw1-f54.google.com with SMTP id n184so9895654ywc.3 for ; Tue, 14 Jan 2020 11:22:41 -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=VmhbnA2uQojITjBbUqjchw4vLkodGBbbRB27sNDqmjk=; b=rUyojWWLldN4wRt4znvTdG+PEf2RKZWJmphVI51v0geYFmZzza0ohO8riezIFYCruB dQHIiZ3mN7GVclkKBVYVufEcvrE4F94nViP2gDxISdZ2SLBaF1pzTf5YgobhW4MfC24s AdOsTbe6KaeI67Gu+aaah3RbDyDErDZ1IKt166CpsfZ5Cz5I6zifaIqTVlU8Lv86TwAn /7U0GOiIVUlC9tJ1xkQwvLMFoLfF5v39QA7tFub9noavoE39975AMfzAp3kb7yljFHqu JNi6xZ14GGWwNoWZLLzCp/d42h0dkThIDY/nRF6hUzwOqTe0JKYEvIRFpR2igtkIlwqL hOoQ== 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=VmhbnA2uQojITjBbUqjchw4vLkodGBbbRB27sNDqmjk=; b=OY65fI3MpjL0AH0PXbvyXUJP6sTcQR3Pz07Nef00s2c2yov4yvU5HodsNx6gADvqwA BlzutlZkxoPEv6/vYBxzL1WID1B9Z4Cd7D/q+pKQIxi90ZQVL1dfkZxqb45nJ9GQCfcq bVUXcltp21aKD7qeaJHIBVMX0PUIrdp4lKykbegj9wQaD0/ea7cVr8nBy0wXH+8gXh2A KmBFF1qgOUVwdSvCwi6K3UjD1tOO6GFp5OFeMmA8HOOXT7vDoucZw+jednptfeXE1DyR G76i+9fBsGk/5Vy1/wtdW7/5Hmta50y1D7gjenhD1NrDpD72/aeOgnK3PZqgX5KEEJ3L U8rw== X-Gm-Message-State: APjAAAUhQPIwYXi2+upCyT2wVE/n4GvJ3TKYrAFvuumfOjazTcSSkDLV uhfl8TtfqsTI/ctoFWd7/SH5mQywJphZmQ== X-Google-Smtp-Source: APXvYqxzWQHT/DgVILc2WshewfVTGaX5YiaYhSG3nffprJPcrcKOPdzOBruEqD46I0IsDw7cb1ejkQ== X-Received: by 2002:a81:5207:: with SMTP id g7mr18281382ywb.428.1579029760057; Tue, 14 Jan 2020 11:22:40 -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 205sm7240995ywm.17.2020.01.14.11.22.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jan 2020 11:22:38 -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: <2502e68d-a1bc-41c6-9763-8c0e2ac9e6f4@www.fastmail.com> Date: Tue, 14 Jan 2020 14:22:38 -0500 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <2502e68d-a1bc-41c6-9763-8c0e2ac9e6f4@www.fastmail.com> 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 14, 2020, at 1:10 PM, Larry Garfield = wrote: >> I get your concern about recursion, but if that kind of issue is = really=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? >=20 > It's not recursion itself that's an issue. It's that the behavior of = the code changes between preload and non-preload contexts in subtle, = non-obvious ways. >=20 > 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 = preloaded. So whether or not foo.php was run through = opcache_compile_file() changes when and how code in that file will fail. = That's the situation we want to avoid like the plague, IMO. With respect, that feels like you are concerned about some real edge = cases, and ignoring the probability that most code run during preloading = would be written bespoke for preloading. ALSO, I think I may have caused confusion by calling it "preloading." = In my mind that meant "run once" vs. "run for each page load" but I = think you are (rightly) conflating what I have called "preloading" with = the new preloading feature in PHP 7.4? What I have been envisioning is a `preload` (or some other) keyword that = we could apply to functions, methods, and expressions. When `preload` = modified functions/methods/expressions are reached during OpCode = generation, rather than generate a call to runtime code PHP would just = run the code and then take the return value and generate OpCode for that = return value.=20 class Foo { preload function bar() { return < a_really_time_consuming_expression>; } } $foo =3D new Foo(); echo $foo->bar(); // This would not actually execute anything at = runtime.=20 // It would simply echo the constant value = that was // returned by = . I could be wrong but I find it hard to believe the runtime profile would = be so different in this context as to create problems of the nature you = are fearing. =20 Maybe someone like Dimitry who understand the OpCode generation process = could weigh in? >> 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 = PHP such=20 >> as by generating OpCode files that a userland developer could load. =20= >=20 > That... sounds a lot like the new FFI extension? Write code in C or = Rust or anything that can produce a .so file, plug it into PHP, go? Unless I am misunderstanding, using an .so requires a sysadmin to add an = extension and update php.ini. Which is a non-starter on hosted sites = like Pantheon, WPEngine, Kinsta, Pagely, Flywheel, PressLabs and = similar. What I was instead calling for what a way to extend PHP that a userland = developer with no access to php.ini would be able to achieve. Interestingly, after my above comment I googled and came across this PHP = extension that can load a compiled Web Assembly (.wasm) file. Something = like this in core would be very useful: https://github.com/wasmerio/php-ext-wasm -Mike