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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 04:01:38 2025 UTC