What this thread does
Do first: call headers_sent($filename, $line) immediately before the failing header operation and inspect the reported output origin.
Short answer
As of November 2026, PHP 8.5.13 is dated November 19, 2026 in the changelog (checked 2026-11-24); this card follows current PHP manual behavior. Cannot modify header information - headers already sent means output has already committed the header block. Remove accidental output or move intentional rendering after header decisions; buffering only delays that commitment (headers_sent).
Choose / don't choose
- Remove output directly: choose for whitespace, a byte-order mark, debugging output or an early template include; don't add a buffer merely to conceal a control-flow error (header).
- Intentional buffering: choose when rendering must be captured before a header decision; start
ob_start()before that rendering. Don't expect it to retract headers already sent (buffer API). - Production diagnostics: choose logging with display disabled; don't let a warning become response content before a redirect (error settings).
Not for: Laravel endpoint performance diagnosis; see laravel-speed-up-slow-page-endpoint-query-or-php-profile.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
output_buffering | On enables buffering; output_buffering=4096 is the documented example; manual default 0; always Off in CLI | Current PHP web SAPI docs | configuration |
display_errors | Off in production; php.ini-production sets it to Off | Current PHP docs | error settings |
log_errors | Use error logging in place of error displaying on production web sites; configure a usable server/file logging destination | Current PHP docs | error settings |
display_startup_errors | Keep Off except when debugging | Current PHP docs | error settings |
headers_sent($filename, $line) | true means HTTP headers have already been sent; output arguments identify where output began; filename can be empty for pre-script startup output | Current PHP docs | API |
ob_start() / chunk_size | Start before output; default 0 buffers until the buffer is ended/flushed rather than a positive-size threshold | Current PHP docs | buffer API |
Order of operations
1. Load only bootstrap code that emits no body. Configure production logging at the server/configuration level; runtime display_errors has no effect on fatal errors when its runtime action does not execute (errors). 2. Call session_start() before body output when cookie-based sessions are used, then perform any session-dependent decisions. Call setcookie() and header() before output as well. There is no universal relative order between independent cookie and header calls: their shared requirement is preceding the body (session, cookies). 3. For a redirect, send header('Location: http://www.example.com/') with the real destination and then exit; the header call alone does not stop later rendering (header). 4. Render the body only after header decisions. If buffering is intentional, account for explicit flush/end calls and its size threshold; once bytes leave the buffer, the original ordering problem can reappear (buffering).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
headers already sent | HTML or blank lines preceded a header | Use the output-origin location, remove premature bytes, move rendering later | header manual |
headers already sent | UTF-8 BOM may be invisible in text editors | Save PHP source without BOM | mario's answer, error settings |
The dated discussion also includes phihag's explanation that buffering does not remove the need to find the early body output. headers_sent() returns false if no HTTP headers have been sent; this does not validate rendering order.
Missing
- Buffering defaults can be changed by the host; the active web SAPI configuration and any framework flush behavior are application-specific.
Checked
2026-11-12; PHP 8.5.12 changelog and current manual, November 2026. Header, cookie, session, output/error configuration, buffer API and the dated mario/phihag discussion read. No PHP requests or configuration changes executed.
Started from a post by @PHP Documentation Group, packaged by the editor. Original post