$ show php/php-src
php-src is the canonical source of the PHP programming language runtime. In production it executes PHP scripts through a pipeline of lexing, parsing, AST construction, opcode compilation, optimization, and execution on a custom virtual machine (the Zend Engine), with an optional JIT compiler provided by OPcache. It ships multiple server APIs (SAPIs): CLI, FastCGI Process Manager (FPM) for web serving, CGI, an Apache 2 module, LiteSpeed, an embeddable SAPI, an interactive debugger (phpdbg), and a fuzzer harness. The standard library spans roughly 80 bundled extensions covering databases (PDO, mysqli, sqlite3), cryptography (openssl, sodium, hash), web protocols (curl, sockets, filter), text processing (mbstring, intl, pcre), and data formats (json, xml, dom, phar, zip). The architecture is a modular C codebase. The Zend Engine (Zend/) implements the language core: the zval value system, a custom memory allocator, garbage collector, highly optimized hash tables, the object model, fibers, and a 16-pass SSA-based optimizer (Zend/Optimizer/) that feeds OPcache's shared-memory script cache and JIT. Extensions register functions, classes, and stream wrappers through a uniform zend_module_entry interface; function signatures are declared in .stub.php files and compiled into generated arginfo headers. The streams layer (main/streams/) provides a uniform I/O abstraction, and TSRM provides thread safety. The build system is autoconf-based with re2c and bison generating scanners and parsers. Primary data flows: PHP source text enters the re2c/bison-generated scanner and parser, producing an AST that the compiler lowers to opcodes; the optimizer performs type inference, dead code elimination, SCCP, and control-flow analysis before the VM executes. OPcache persists compiled scripts in shared memory, and the JIT translates hot traces to native code. Requests flow through the SAPI lifecycle (RINIT, script execution, RSHUTDOWN). Build dependencies include autoconf, bison, re2c, and optional system libraries (ICU, OpenSSL, libxml2, libcurl, libsqlite); several libraries are vendored in-tree (PCRE2/SLJIT, libgd, libmagic, timelib, uriparser, lexbor, boost.context, Keccak). The codebase is exceptionally well maintained: near-daily commits, extensive CI across Linux, macOS, Windows, and FreeBSD, a regression suite of over 20,000 .phpt tests, fuzzing infrastructure, and a formal security response process. The engineering quality is world-class; the hash table, allocator, VM, and optimizer are studied as reference implementations. This is not a conventional reusable library (it is the runtime itself), but its vendored components, test harness, and extension patterns are independently reusable.
The LLM identified 6 files worth highlighting for reuse:
A standalone RFC 3986 URI parser vendored into PHP. It compiles once for ANSI and once for Unicode via a self-inclusion pattern, exposes a pluggable memory manager (UriMemoryManager), and provides well-formedness validation plus per-component setters. It has zero dependencies on the Zend Engine and can be extracted into any C project as-is.
timelib is a self-contained C library for date/time parsing, formatting, timezone conversion using the IANA tz database, and calendar math. It is also used outside PHP by MongoDB, proving its independence. It can be dropped into any C project for robust date/time handling.
Vendored boost.context assembly routines providing fiber context switch and make operations for 15+ CPU/ABI/OS combinations (x86_64, ARM64, RISC-V, s390x, and more). This is the low-level substrate for PHP fibers and consists of standalone per-platform assembly files with a tiny C API, directly reusable in any coroutine or fiber implementation.
Implements the gamma-section algorithm for generating uniformly distributed random floats over arbitrary intervals with correct rounding. It is a small, self-contained, mathematically non-trivial routine with no Zend Engine dependencies beyond basic integer types, and can be lifted into any RNG library.
The .phpt test runner used across the entire PHP ecosystem, including third-party extensions. It parses test files with --TEST--, --FILE--, --EXPECT--, --SKIPIF--, --INI--, and --CLEAN-- sections, runs them in isolated subprocesses, and produces TAP-like output. It is a self-contained PHP script demonstrating a robust, convention-driven test harness pattern.
SLJIT is a platform-independent JIT compiler that generates native code for x86, ARM, RISC-V, MIPS, and other architectures, with per-OS W^X executable memory allocators. Vendored for PCRE2's JIT support, it is a standalone library with a documented API and can be extracted for any project needing dynamic code generation.