HOW CGI WORKS 1. Web server parses request from client 2. Web server sets request info into environment (PATH_INFO, REQUEST_METHOD, HTTP_ACCEPT, …) 3. Web server executes CGI script 4. CGI script echos status, headers, and body 5. Web server returns response to client
PHP WEB SAPI (SIMPLIFIED) • populate $_SERVER and $_ENV • parse QUERY_STRING into $_GET • " application/x-www-form-urlencoded into $_POST • " multipart/form-data into $_FILES • return header() data as headers, anything echo()d as content
APACHE PROCESS MODELS • mpm_prefork creates worker processes (each with a PHP) • mpm_worker uses threads (so you need ZTS, and stuff will generally crash a lot) • mpm_event uses an event loop (best, but you can't embed something like PHP at all)
PHP IS NOW READY • PHP 7+ performance is amazing • Almost all engine errors are catchable since PHP 7 • Signal handling without ticks in PHP 7.1 • Concurrency frameworks and event lib extensions