Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127694 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id D22A11A00BC for ; Mon, 16 Jun 2025 20:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1750103956; bh=AsGeHxO89v5sR5IfQocTMNy47GkrazLCINx9mOGsjY4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=mBcqf4CWp8AMBmTDO9MehBm8hE2yGpjBcUqEtOztX8XWPw8qTcZ3WeYXK/prpLdgs Kpnf+1eQ8OhyJJwtMT+pgai5Ue776o6TXQITCwGN09eVTW/wGlyTreqThBYVN8Fae+ MVuEsPvIEj/aIRUqW91fW4ymbFzN3Ha/WHx2k6ZdhVC8S3rqRzwpB4ghp7/mDH4HUk m+6rZ1kH2pth4bZQv/pXIMR6nmG+PNMaO1F7NkBCZ92LBSRXZvOmxHKwSK4cLpcaDl nEkw+E3sS9bDHq9U7e/c7G/juRiJosGZS6iw87MjFsINAB0DmAvlcofpR9SYj4yISt qAKpxSIt2hCJQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BAADF18004A for ; Mon, 16 Jun 2025 19:59:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 16 Jun 2025 19:59:12 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id EAF491380370 for ; Mon, 16 Jun 2025 16:01:10 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-05.internal (MEProxy); Mon, 16 Jun 2025 16:01:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1750104070; x=1750190470; bh=AsGeHxO89v 5sR5IfQocTMNy47GkrazLCINx9mOGsjY4=; b=CVfhcgHKHikO0f35YDWSFVGHSK w4dDp6iHCtsd8ei1GFD35L9OZGZxNqb8quqbfq1oKP2kr6OJJRyx/CRyAwlhvJFm v4E4JxXwuCFhG0s3wBHMfS4nrh3NJcGrVSi7UqvBBzEMjlWkbabwFZ/4VDvQkm4i 5GHaoFDwWRIy+UPvaYRV1+MimpGSTZZXOpoN7L6r+4jwSCJ+ZU+W804aI9YdtE9h jq25qqXfrEI74JbNMe1il9KiiJAw+H+DU0bBgp+tMOJicebjCxIaaGa0us+Gw5V7 8hmEQ0SITV7hErfWo5e/lumzPk7holD3othN4V9mlGGFXwELGijbRiNAaFqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1750104070; x=1750190470; bh=AsGeHxO89v5sR5IfQocTMNy47GkrazLCINx 9mOGsjY4=; b=SWM8kFJ1tKCjBsQhfLhicGgb0vscHPeb6Y9YQi6XY9bp6dsVxWW rOOnwXGJcyMBzN2hR9+VyolG8wdxwevsiMu+uSnrslYfHGALfLVYiRQf1Kl8Z8p/ kmn7pxmhA9unhgMPK4rnbnr7thGlmdb9MP1isX/qyROMYOHGHPsxdrtXHYY4O7gk 6ORSTZx40vJvBtJK6lAmLAIprt6L8LZHP0LGxGKZzOYpCH1oxIgzAT55iDJBYIZ8 f+lyP76ewBwRFihGWPirYnTbMtGg3EyW87U+kUVKEq5jRpugJYUkABy1FbUPk5oF 3aOk7XgMZM4xQxXkXGMcDvbTThKcLYiEigQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugddvjeeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggff fhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdf uceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnheptdeuje dttefhueelhfdtleeiudetlefftdduleehffegtdeihefhleeijefgveegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlh gvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 766EA2400094; Mon, 16 Jun 2025 16:01:10 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Te0bb3aa588644ddd Date: Mon, 16 Jun 2025 22:00:50 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] RFC Discussion - CLI-Only Development Mode and AOT Compilation Architecture Content-Type: multipart/alternative; boundary=7daf99f6b4a3469e9221f42ebd021a3e From: rob@bottled.codes ("Rob Landers") --7daf99f6b4a3469e9221f42ebd021a3e Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jun 16, 2025, at 09:05, wheakerd wrote: > Dear PHP Internals, >=20 > I am submitting this proposal for discussion regarding a potential fut= ure direction for PHP: moving toward a CLI-only development model and in= troducing an optional Ahead-of-Time (AOT) compilation infrastructure. >=20 > While this may not fully align with PHP=E2=80=99s traditional interpre= ter-based design, I believe it opens up valuable opportunities to modern= ize PHP's runtime and improve performance, portability, and long-term ma= intainability. We kinda already have this =E2=80=94 to a degree. You can enable pre-loa= ding and OPcache. In case you aren=E2=80=99t aware (I wasn=E2=80=99t jus= t a year ago!) OPcache is quite advanced and does much of the same stuff= a traditional compiler does: (transforms the source into an IR and can = even run SSA on it =E2=80=94 assuming I read the extension correctly, an= d I=E2=80=99m fairly confident in that). > =3D=3D=3D=3D=3D Current Development Landscape =3D=3D=3D=3D=3D > Contemporary PHP projects are already moving toward architecture patte= rns that resemble compiled systems: >=20 > - Frameworks define service containers, dependency graphs, and code ge= neration layers. > - Static analysis tools (Psalm, PHPStan) are integral to modern develo= pment. > - Code is often bootstrapped through CLI pipelines: for build, testing= , deployment, and even request simulation (`php artisan`, `bin/console`,= etc.). > - Composer autoloading, annotation processors, and classmaps are preco= mputed. > - Web servers (e.g., Swoole, RoadRunner) are replacing FPM in performa= nce-critical applications, with CLI processes becoming long-lived daemon= s. >=20 > All of this reflects a growing shift: **PHP is increasingly behaving l= ike a static backend language**, except it still runs on a dynamic inter= preter. >=20 > This proposal attempts to provide native language support and compiler= infrastructure that aligns with these modern PHP usage patterns. I=E2=80=99m unsure why you=E2=80=99re asserting that compiled systems on= ly use these architectural patterns? They=E2=80=99re patterns and thus c= an be used in JavaScript, or even Lisp, if you want to. It doesn=E2=80=99= t mean the language has to be compiled to generate code (in fact, were i= t a compiled language, generating code would be nigh impossible during r= untime). >=20 > =3D=3D=3D=3D=3D Motivation =3D=3D=3D=3D=3D > PHP=E2=80=99s traditional runtime model (FPM or mod_php) is optimized = for short-lived, script-based execution. However, this limits PHP=E2=80=99= s potential in: >=20 > - Serverless or event-driven environments (high cold start cost). > - Embedded targets and containers with limited runtime support. > - Modular system design where PHP extensions must be written in C. > - Distributable binaries for CLI tools or desktop-style apps. >=20 > PHP developers are often forced to work around these limitations using= complex workarounds (e.g., caching containers, annotation scans, custom= autoloaders, preload hacks). AOT compilation and CLI-first design can s= olve these challenges directly, natively. I=E2=80=99m sorry; you=E2=80=99ve lost me here.=20 How does "short-lived" execution fail in serverless or event-driven envi= ronments? Isn=E2=80=99t that the entire point? Serverless is basically a= reinvention of CGI, which PHP excels at. However, the people who built = these runtimes didn=E2=80=99t realise what they were reinventing to run = long-lived applications and didn=E2=80=99t include PHP because "PHP is d= ying" for the last 20 years. This is a failure of the people who built t= he runtimes, not PHP=E2=80=99s execution model. It is a political issue,= not a technical one. I primarily work with embedded PHP, there is even an ancient book about = it (which is how I first got into php-src). Embedded PHP is where it is = at if you ask me. It is a great language for it, especially because ther= e is a lot of PHP talent out there quite used to dealing with "shared no= thing", "stateless", "event driven" architecture. Then there is the fact that PHP extensions must be written in C. This is= a false assertion. They may also be written in C++, or any language tha= t can bind with C libraries (like Go, Zig, Rust, or even C#). Also, it is false that you can=E2=80=99t distribute CLI tools written in= PHP. There is at least one project that lets you bundle your PHP projec= t in a statically built, self-extracting executable. > =3D=3D=3D=3D=3D Proposal =3D=3D=3D=3D=3D > ### 1. Compiler Infrastructure (AOT Mode) > A new compiler pipeline would be introduced: >=20 > - **Frontend**: Parse PHP source into AST (reusing current infrastruct= ure). > - **IR Layer**: Transform AST into intermediate representation (IR). > - **Backend**: Compile IR into native binary via C transpilation or LL= VM backend. >=20 > ### 2. Required Language Model Changes > To make PHP compilable in AOT mode, certain dynamic features must be r= estricted or restructured. The following are required: >=20 > #### a. **Static Code & Configuration** > - Dynamic constructs (e.g., `eval`, dynamic includes/classes/functions= ) are disallowed. > - Project must provide static configuration file (`php.compiler.json`)= for classmap, entrypoint, environment constants, etc. > - No runtime-based code discovery or composition. >=20 > #### b. **Unified Standard Library** > - Procedural global functions (e.g., `strlen`, `array_merge`) are cons= olidated into base classes (e.g., `Str::len()`, `Arr::merge()`). > - Modules gain clearer boundaries and dependency injection support. >=20 > #### c. **Environment Interfaces** > - Superglobals (`$_ENV`, `$_SERVER`, etc.) are abstracted via interfac= es or injectable system services. >=20 > #### d. **Type System Enhancements** > - Strong use of `declare(strict_types=3D1)`, interfaces, final classes= , and property types. > - Optional compilation-time type enforcement and inference. >=20 > #### e. **Compiler Extension Hooks** > - Developers or frameworks can hook into compilation stages (AST trans= formation, IR passes) to generate optimized artifacts. >=20 > ### 3. CLI-Only Development Focus > - CLI becomes the canonical platform for PHP execution and development. > - PHP-FPM and SAPI models remain available for backward compatibility = but are **not required** for future application delivery. > - Built-in CLI runners or Web adapters (e.g., `php serve`, Swoole adap= ters) provide development/testing environments. >=20 > =3D=3D=3D=3D=3D Expected Benefits =3D=3D=3D=3D=3D > - Native, standalone executables=E2=80=94no PHP interpreter dependency. > - Fast cold start (useful in serverless and event-driven environments). > - PHP extensions can be authored in PHP and compiled, removing the C b= arrier. > - Clean separation between compilation-time and runtime. > - Enables new use cases: embedded systems, WASM targets, mobile SDKs, = long-lived CLI daemons. You would still be dependent upon the PHP runtime environment. Much like= the C# CLR. There is nothing stopping someone from working on OPcache t= o its natural conclusion and getting the machine code out of it, into a = file that can run directly. However, you=E2=80=99re still going to want = to run your old code, which most likely calls "exec" somewhere (to compi= le a twig template), or uses autoloading shenanigans to mock out code, o= r DI systems that generate new code on demand when you make changes. >=20 > =3D=3D=3D=3D=3D Compatibility Note =3D=3D=3D=3D=3D > This proposal is entirely opt-in and defines a **strict static subset = of PHP**. Dynamic runtime via Zend VM and JIT continues to be supported = and unchanged. This is an addition, not a replacement. >=20 > =3D=3D=3D=3D=3D Request for Feedback =3D=3D=3D=3D=3D > I=E2=80=99d appreciate feedback from internals and community members o= n: >=20 > - Whether such a compiler pipeline is desirable and feasible. > - Acceptability of the required language subset restrictions. > - Pathways to prototype this outside core, e.g., via PHP extensions or= userland tooling. You may be interested in kphp, which compiles a subset of PHP to machine= code. It is still actively developed and maintained. It is a pretty int= eresting project and has stood the test of time.=20 >=20 > =3D=3D=3D=3D=3D Note =3D=3D=3D=3D=3D > I would like to clarify that I am currently not in a position to imple= ment this proposal independently, as it would involve deep modifications= to the PHP runtime, compiler pipeline design, or extension interfaces. >=20 > This RFC is submitted with the intention of initiating structured disc= ussion and community exploration around this long-term direction. I am w= illing to contribute research, coordination, and specification work if t= here is interest from core contributors. >=20 > I greatly appreciate any feedback, suggestions, or interest in collabo= rating on prototyping or feasibility assessment. >=20 > Sincerely,=20 > [wheakerd] =E2=80=94 Rob --7daf99f6b4a3469e9221f42ebd021a3e Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Mon, Jun 16, 2025, at 09:05, wheakerd wrote:
<= blockquote type=3D"cite" id=3D"qt" style=3D"">
Dear PHP Internals,

I am submitting = this proposal for discussion regarding a potential future direction for = PHP: moving toward a CLI-only development model and introducing an optio= nal Ahead-of-Time (AOT) compilation infrastructure.

=
While this may not fully align with PHP=E2=80=99s traditional inter= preter-based design, I believe it opens up valuable opportunities to mod= ernize PHP's runtime and improve performance, portability, and long-term= maintainability.

We k= inda already have this =E2=80=94 to a degree. You can enable pre-loading= and OPcache. In case you aren=E2=80=99t aware (I wasn=E2=80=99t just a = year ago!) OPcache is quite advanced and does much of the same stuff a t= raditional compiler does: (transforms the source into an IR and can even= run SSA on it =E2=80=94 assuming I read the extension correctly, and I=E2= =80=99m fairly confident in that).

=3D=3D= =3D=3D=3D Current Development Landscape =3D=3D=3D=3D=3D
Contem= porary PHP projects are already moving toward architecture patterns that= resemble compiled systems:

- Frameworks define= service containers, dependency graphs, and code generation layers.
- Static analysis tools (Psalm, PHPStan) are integral to modern de= velopment.
- Code is often bootstrapped through CLI pipelines:= for build, testing, deployment, and even request simulation (`php artis= an`, `bin/console`, etc.).
- Composer autoloading, annotation = processors, and classmaps are precomputed.
- Web servers (e.g.= , Swoole, RoadRunner) are replacing FPM in performance-critical applicat= ions, with CLI processes becoming long-lived daemons.

All of this reflects a growing shift: **PHP is increasingly behav= ing like a static backend language**, except it still runs on a dynamic = interpreter.

This proposal attempts to provide = native language support and compiler infrastructure that aligns with the= se modern PHP usage patterns.

I=E2=80=99m unsure why you=E2=80=99re asserting that compiled sy= stems only use these architectural patterns? They=E2=80=99re patterns an= d thus can be used in JavaScript, or even Lisp, if you want to. It doesn= =E2=80=99t mean the language has to be compiled to generate code (in fac= t, were it a compiled language, generating code would be nigh impossible= during runtime).


=3D=3D= =3D=3D=3D Motivation =3D=3D=3D=3D=3D
PHP=E2=80=99s traditional= runtime model (FPM or mod_php) is optimized for short-lived, script-bas= ed execution. However, this limits PHP=E2=80=99s potential in:

- Serverless or event-driven environments (high cold sta= rt cost).
- Embedded targets and containers with limited runti= me support.
- Modular system design where PHP extensions must = be written in C.
- Distributable binaries for CLI tools or des= ktop-style apps.

PHP developers are often force= d to work around these limitations using complex workarounds (e.g., cach= ing containers, annotation scans, custom autoloaders, preload hacks). AO= T compilation and CLI-first design can solve these challenges directly, = natively.

I=E2=80=99m = sorry; you=E2=80=99ve lost me here.

How does "= short-lived" execution fail in serverless or event-driven environments? = Isn=E2=80=99t that the entire point? Serverless is basically a reinventi= on of CGI, which PHP excels at. However, the people who built these runt= imes didn=E2=80=99t realise what they were reinventing to run long-lived= applications and didn=E2=80=99t include PHP because "PHP is dying" for = the last 20 years. This is a failure of the people who built the runtime= s, not PHP=E2=80=99s execution model. It is a political issue, not a tec= hnical one.

I primarily work with embedded PHP,= there is even an ancient book about it (which is how I first got into p= hp-src). Embedded PHP is where it is at if you ask me. It is a great lan= guage for it, especially because there is a lot of PHP talent out there = quite used to dealing with "shared nothing", "stateless", "event driven"= architecture.

Then there is the fact that PHP = extensions must be written in C. This is a false assertion. They may als= o be written in C++, or any language that can bind with C libraries (lik= e Go, Zig, Rust, or even C#).

Also, it is false= that you can=E2=80=99t distribute CLI tools written in PHP. There is at= least one project that lets you bundle your PHP project in a statically= built, self-extracting executable.

=3D= =3D=3D=3D=3D Proposal =3D=3D=3D=3D=3D
### 1. Compiler Infrastr= ucture (AOT Mode)
A new compiler pipeline would be introduced:=

- **Frontend**: Parse PHP source into AST (reu= sing current infrastructure).
- **IR Layer**: Transform AST in= to intermediate representation (IR).
- **Backend**: Compile IR= into native binary via C transpilation or LLVM backend.

<= /div>
### 2. Required Language Model Changes
To make PHP c= ompilable in AOT mode, certain dynamic features must be restricted or re= structured. The following are required:

#### a.= **Static Code & Configuration**
- Dynamic constructs (e.g= ., `eval`, dynamic includes/classes/functions) are disallowed.
- Project must provide static configuration file (`php.compiler.json`) = for classmap, entrypoint, environment constants, etc.
- No run= time-based code discovery or composition.

#### = b. **Unified Standard Library**
- Procedural global functions = (e.g., `strlen`, `array_merge`) are consolidated into base classes (e.g.= , `Str::len()`, `Arr::merge()`).
- Modules gain clearer bounda= ries and dependency injection support.

#### c. = **Environment Interfaces**
- Superglobals (`$_ENV`, `$_SERVER`= , etc.) are abstracted via interfaces or injectable system services.

#### d. **Type System Enhancements**
- S= trong use of `declare(strict_types=3D1)`, interfaces, final classes, and= property types.
- Optional compilation-time type enforcement = and inference.

#### e. **Compiler Extension Hoo= ks**
- Developers or frameworks can hook into compilation stag= es (AST transformation, IR passes) to generate optimized artifacts.

### 3. CLI-Only Development Focus
- CLI b= ecomes the canonical platform for PHP execution and development.
- PHP-FPM and SAPI models remain available for backward compatibility= but are **not required** for future application delivery.
- B= uilt-in CLI runners or Web adapters (e.g., `php serve`, Swoole adapters)= provide development/testing environments.

=3D=3D= =3D=3D=3D Expected Benefits =3D=3D=3D=3D=3D
- Native, standalo= ne executables=E2=80=94no PHP interpreter dependency.
- Fast c= old start (useful in serverless and event-driven environments).
- PHP extensions can be authored in PHP and compiled, removing the C b= arrier.
- Clean separation between compilation-time and runtim= e.
- Enables new use cases: embedded systems, WASM targets, mo= bile SDKs, long-lived CLI daemons.
You would still be dependent upon the PHP runtime environme= nt. Much like the C# CLR. There is nothing stopping someone from working= on OPcache to its natural conclusion and getting the machine code out o= f it, into a file that can run directly. However, you=E2=80=99re still g= oing to want to run your old code, which most likely calls "exec" somewh= ere (to compile a twig template), or uses autoloading shenanigans to moc= k out code, or DI systems that generate new code on demand when you make= changes.


=3D=3D=3D= =3D=3D Compatibility Note =3D=3D=3D=3D=3D
This proposal is ent= irely opt-in and defines a **strict static subset of PHP**. Dynamic runt= ime via Zend VM and JIT continues to be supported and unchanged. This is= an addition, not a replacement.

=3D=3D=3D=3D=3D= Request for Feedback =3D=3D=3D=3D=3D
I=E2=80=99d appreciate f= eedback from internals and community members on:

- Whether such a compiler pipeline is desirable and feasible.
- Acceptability of the required language subset restrictions.
- Pathways to prototype this outside core, e.g., via PHP extensions or= userland tooling.

You= may be interested in kphp, which compiles a subset of PHP to machine co= de. It is still actively developed and maintained. It is a pretty intere= sting project and has stood the test of time. 

=
=3D=3D=3D=3D=3D Note =3D=3D=3D=3D=3D
I would = like to clarify that I am currently not in a position to implement this = proposal independently, as it would involve deep modifications to the PH= P runtime, compiler pipeline design, or extension interfaces.
=
This RFC is submitted with the intention of initiating st= ructured discussion and community exploration around this long-term dire= ction. I am willing to contribute research, coordination, and specificat= ion work if there is interest from core contributors.

I greatly appreciate any feedback, suggestions, or interest in co= llaborating on prototyping or feasibility assessment.
Sincerely, 
[wheakerd]

=E2=80=94 Rob
--7daf99f6b4a3469e9221f42ebd021a3e--