Skip to content

Web: Runtime-populated superglobals for JIT and AOT (per-request $_GET/$_POST) #49

@PurHur

Description

@PurHur

Problem

lib/JIT/SuperglobalInit.php copies superglobals from the VM context at compile/init time into LLVM globals (sg_GET, etc.). For AOT, bin/compile.php -q 'name=World' bakes query data into the binary—see examples/001-SimpleWeb/example.php comments and test/fixtures/aot/cases/simple_web_get.phpt.

A real web server invokes the same binary per request with different QUERY_STRING / POST body. Today that requires recompiling or using VM mode only.

Goal

Support runtime superglobal population in JIT and AOT standalone binaries.

Design sketch

  1. At process start (or per CGI request), parse QUERY_STRING / stdin POST via C/LLVM helpers or a small runtime init calling into existing PHPCompiler\Web\Superglobals logic ported to native code.
  2. Replace compile-time-only SuperglobalInit::populateFromVm with:
    • AOT: init function __superglobals_init() called from main before user code
    • JIT embed: refresh globals when CLI passes -q/-p each run (already partially true via VM pre-populate)
  3. Keep optional compile-time specialization when -q is passed (optimization, not requirement)

Tasks

  • C/LLVM: form-urlencoded parser (or link minimal parser) for GET/POST
  • Populate sg_* globals from env (getenv) in standalone binaries
  • VM path unchanged; document behavior difference vs AOT
  • PHPT: AOT binary run without recompile, two different QUERY_STRING values → different output
  • Update IssetHelper / empty() for dynamic keys (not only compileTimeOffsetIsSet)

Acceptance criteria

./compiled_binary with QUERY_STRING=name=Alice and QUERY_STRING=name=Bob produces different HTML without re-running bin/compile.php.

Key files

  • lib/JIT/SuperglobalInit.php
  • lib/Web/Superglobals.php
  • bin/compile.php, bin/jit.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions