ralouphie/getallheaders
Polyfill for PHP’s getallheaders() providing a consistent way to retrieve HTTP request headers across SAPI environments (CLI, built-in server, FPM, etc.). Lightweight, framework-agnostic, commonly used in PSR-7/HTTP tooling.
This package is a polyfill for PHP’s getallheaders() function, which is not available in all SAPIs (notably, not in FastCGI Process Manager — FPM). To use it:
composer require ralouphie/getallheaders
getallheaders() as usual — the polyfill auto-registers and detects if the native function exists; if not, it provides a compatible implementation.getallheaders() would otherwise fail silently or throw a fatal error.getallheaders() in a service class (e.g., RequestHeaders) to decouple from the polyfill and improve testability.phpunit.xml or bootstrap files, include a conditional check to load the polyfill only when needed (function_exists('getallheaders') || require 'vendor/autoload.php').$_SERVER variables, so avoid calling getallheaders() in tight loops — caching the result is recommended if used repeatedly.X-Request-Id → X-Request-Id), but custom SAPIs (e.g., some FastCGI configurations) may use inconsistent $_SERVER prefixes (HTTP_, REDIRECT_HTTP_, etc.). Verify $_SERVER content in non-standard environments.getallheaders() (e.g., via another polyfill or manually), Composer won’t warn — you may get redeclaration errors. Use class_exists() or Composer’s replace section to avoid duplicate polyfills.How can I help you explore Laravel packages today?