|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68207 Setting fastcgi.error_header can result in an E_WARNING being triggered
Submitted: 2014-10-10 14:07 UTC Modified: -
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nj506 at zepler dot net Assigned:
Status: Open Package: FPM related
PHP Version: 5.5.17 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-10-10 14:07 UTC] nj506 at zepler dot net
With fastcgi.error_header set to some value (e.g. "HTTP/1.1 500 Internal Server Error"), PHP-FPM will attempt to set the header value when the PHP exit status is determined to be 255 -

If headers have already been sent, then an E_WARNING is triggered by sapi_header_op -

As such, if headers have been sent (e.g. due to output), then at some point PHP sets the exit_status value to 255 (e.g. due to an error), and fastcgi.error_header is set to some value, then an E_WARNING will be triggered.

This seems undesirable - perhaps it should simply not attempt to call sapi_header_op if headers have already been sent?

Test script:

// With fastcgi.error_header set to "HTTP/1.1 500 Internal Server Error"

echo 'x';

register_shutdown_function(function() {
    file_put_contents('/tmp/error', print_r(error_get_last(), true));

z(); // trigger a fatal error

Expected result:
A fatal error will be triggered, and the last error visible when shutting down will be the fatal.


$ cat /tmp/error
    [type] => 1
    [message] => Call to undefined function z()
    [file] => .../test.php
    [line] => 7

Actual result:
PHP-FPM attempts to replace the header, but headers have already been sent (due to output):

$ cat /tmp/error
    [type] => 2
    [message] => Cannot modify header information - headers already sent by (output started at test.php:3)
    [file] => Unknown
    [line] => 0


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jun 30 06:03:48 2022 UTC