Skip to content

Web: JIT/AOT mode for bin/serve.php (compile per script on first request) #207

@PurHur

Description

@PurHur

Problem

bin/serve.php always uses VM (Runtimelib/VM.php). Dev servers for Zend PHP often use OPcache; we have JIT (#153 cache) but no serve integration.

Contributors benchmarking 001-SimpleWeb cannot compare VM vs JIT latency under real HTTP without manually invoking bin/jit.php per script. 003-MiniWebApp phpc serve --jit remains blocked on project includes (#475, #1770) even after OOP compliance lands.

Goal

phpc serve --jit 127.0.0.1:8080 examples/001-SimpleWeb

Compiles .php scripts with bin/jit.php on first hit, caches (#153), falls back to VM on compile error. Output must match VM for the same request (superglobals, headers, static files).

Blocker matrix (May 2026)

Blocker Issue Status Unblocks
Static include in JIT #475 open flat examples 001
Project graph JIT #1770 open 003 multi-file
Runtime superglobals in JIT #49 partial per-request $_GET/$_POST
On-disk JIT cache #153 open warm second request
Serve tests in CI #234 closed local ci-local.sh

Not required for North Star 1 — VM + AOT execute already green (#1044 ✅).

Implementation hints

Area Files Notes
CLI bin/phpc.php, bin/serve.php --jit flag; document in phpc serve --help
Request path lib/Web/DevServer.php On cache miss: bin/jit.php compile → store artifact
Superglobals lib/Web/Superglobals.php, lib/JIT/SuperglobalInit.php Repopulate per request before JIT entry — verify not baked sg_* (#49)
Static assets existing static handler Unchanged — only .php hits JIT
Errors serve 500 mapping #152 JIT compile failure → VM fallback or 500 with PHP_COMPILER_DEBUG
Project mode lib/Web/ProjectManifest.php Defer until #1801 (phpc build --project --jit)

Cache directory layout (v1)

.phpc/jit-cache/<sha256(realpath+mtime)>.so   # or internal JIT artifact format

Invalidate when source file mtime changes.

Tests

Acceptance criteria

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  vendor/bin/phpunit --group serve --filter ServeJit

Second request to same script is faster than first; HTML output matches VM.

Verification (local / Docker only)

./script/ci-local.sh --filter ServeJit

Do not require GitHub Actions.

Dependencies

Links

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions