Bug #68207 [NEW]: Setting fastcgi.error_header can result in an E_WARNING being triggered

From: Date: Fri, 10 Oct 2014 14:07:50 +0000
Subject: Bug #68207 [NEW]: Setting fastcgi.error_header can result in an E_WARNING being triggered
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188007@lists.php.net to get a copy of this message
From:             nj506 at zepler dot net
Operating system: 
PHP version:      5.5.17
Package:          FPM related
Bug Type:         Bug
Bug description:Setting fastcgi.error_header can result in an E_WARNING being triggered

Description:
------------
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 -
https://github.com/php/php-src/blob/f89ee8040a8b8d93981c9df85a79592ceac02f1f/sapi/fpm/fpm/fpm_main.c#L1950-L1958

If headers have already been sent, then an E_WARNING is triggered by
sapi_header_op -
https://github.com/php/php-src/blob/f89ee8040a8b8d93981c9df85a79592ceac02f1f/main/SAPI.c#L675-L686

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:
---------------
<?php

// 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.

e.g.

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68207&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68207&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68207&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68207&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68207&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68207&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68207&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68207&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68207&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68207&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68207&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68207&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68207&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68207&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68207&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68207&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68207&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68207&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68207&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68207&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68207&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#188007) next »