php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79446 Flush() is needed to print headers when execution is terminated
Submitted: 2020-04-03 12:37 UTC Modified: 2020-04-07 18:47 UTC
From: michael dot vorisek at email dot cz Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.4.4 OS:
Private report: No CVE-ID: None
 [2020-04-03 12:37 UTC] michael dot vorisek at email dot cz
Description:
------------
For some reasons headers are not outputted when script is terminated with set_exception_handler().

I was not able to isolate the issue, simple test below does not have it, but the complex example below is repeatable across multiple servers and PHP versions (7.2 - 7.4.4).

Test script:
---------------
# this works even without flush()
header('Content-Type: application/json', true);
echo json_encode('test');
// flush();
set_exception_handler(function (Throwable $t) {return true;});
throw new \Exception();

# but in this code flush() is required, otherwise "text/html; charset=UTF-8" is outputted even if this exact content-type (with charset) is not outputted in this project at at (it has to come from PHP)
https://github.com/atk4/ui/pull/1051/commits/423251f13e515a0dadaed548abe17989cfbf0f33#diff-58980ac23a3a9a0b92abd9805eed1e78R227
CI results prior fixing with flush(): https://github.com/atk4/ui/runs/556304096?check_suite_focus=true#step:9:50

It can be easily reproduced locally when you clone https://github.com/mvorisek/atk4_ui/commit/46411692933745ef7b715c608363393afc803b85 and open URL ./demos/sticky2.php?__atk_reload=atk_admin_button . Issue can be reproduced with fast-cgi and internal php web server.

Expected result:
----------------
Headers, ie. content-type in the example, are always sent even if the execution is immediatelly terminated.

Actual result:
--------------
Headers are not outputed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-07 17:18 UTC] michael dot vorisek at email dot cz
Close this
 [2020-04-07 18:47 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2020-04-07 18:47 UTC] requinix@php.net
Okay?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 00:01:30 2024 UTC