Bug #79446 [NEW]: Flush() is needed to print headers when execution is terminated

From: Date: Fri, 03 Apr 2020 12:37:03 +0000
Subject: Bug #79446 [NEW]: Flush() is needed to print headers when execution is terminated
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226426@lists.php.net to get a copy of this message
From: michael dot vorisek at email dot cz Operating system: PHP version: 7.4.4 Package: Scripting Engine problem Bug Type: Bug Bug description:Flush() is needed to print headers when execution is terminated 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. -- Edit bug report at https://bugs.php.net/bug.php?id=79446&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79446&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79446&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79446&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79446&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79446&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79446&r=support Expected behavior: https://bugs.php.net/fix.php?id=79446&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79446&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79446&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79446&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79446&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79446&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79446&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79446&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79446&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79446&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79446&r=mysqlcfg

« previous php.bugs (#226426) next »