[php-src] PR #23839: sapi: don't crash when SAPI functions are called from opcache.preload

From: Date: Tue, 22 Sep 2026 08:31:15 +0000
Subject: [php-src] PR #23839: sapi: don't crash when SAPI functions are called from opcache.preload
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-38707@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/23839 Author: lacatoire A preload script runs during server startup, before any request, so SG(server_context) is NULL. Several apache2handler functions and SAPI hooks that opcache does not swap out during preloading dereferenced it unconditionally: apache_getenv(), apache_setenv(), apache_note(), apache_request_headers()/getallheaders(), apache_response_headers(), php_apache_sapi_get_stat() (reached by getmyuid()) and php_apache_sapi_read_post() (reached by php://input). Calling any of them from a preload script crashed the server at startup. The cli-server's own apache_request_headers() has the same pattern. Make each of them tolerate a NULL context: the array-returning functions return an empty array, the bool/string-returning ones warn and return false, and the two SAPI hooks return the neutral value their contract already allows for a failure (NULL for get_stat(), 0 bytes read for read_post()), the same way php_apache_lookup_uri() and php_apache_sapi_getenv() already did. The phpinfo() module info section (PHP_MINFO_FUNCTION(apache)) has the same unchecked dereference but needs a broader change to stay useful without a request; left out of this fix.

« previous php.git-pulls (#38707) next »