Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Getallheaders Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Install via Composer:
    composer require ralouphie/getallheaders
    
  2. In code, simply call getallheaders() as usual — the polyfill auto-registers and detects if the native function exists; if not, it provides a compatible implementation.
  3. First use case: accessing all incoming HTTP headers in a framework-agnostic way (e.g., in lightweight microservices, CLI scripts, or custom bootstrap files) where getallheaders() would otherwise fail silently or throw a fatal error.

Implementation Patterns

  • Dependency injection: Wrap getallheaders() in a service class (e.g., RequestHeaders) to decouple from the polyfill and improve testability.
  • Framework integration: In Laravel, use it in middleware or request handlers before or during the request lifecycle to normalize header access — especially when running on nginx+php-fpm or Apache without mod_headers.
  • Testing setup: In phpunit.xml or bootstrap files, include a conditional check to load the polyfill only when needed (function_exists('getallheaders') || require 'vendor/autoload.php').
  • Debugging endpoints: In development tools or diagnostic routes, use it to dump all headers for troubleshooting (e.g., Authorization, X-Request-ID).

Gotchas and Tips

  • Performance: The polyfill reconstructs headers from $_SERVER variables, so avoid calling getallheaders() in tight loops — caching the result is recommended if used repeatedly.
  • Header normalization: The polyfill normalizes keys (e.g., X-Request-IdX-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.
  • Conflict risk: Rarely, if your project already defines 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.
  • Not for outbound requests: This polyfill is strictly for incoming request headers — don’t use it for cURL or Guzzle header inspection.
  • Future-proofing: PHP 7.3+ and modern frameworks (Laravel 6+) usually include native support on common SAPIs, but this polyfill remains valuable for backward compatibility or edge-case environments like embedded PHP or unconventional web servers.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport