php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78565 Shutdown functions are not called when exit is called from output handler
Submitted: 2019-09-19 07:41 UTC Modified: 2022-01-17 11:40 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: video dot ice dot power at seznam dot cz Assigned: cmb (profile)
Status: Duplicate Package: *General Issues
PHP Version: 7.3.9 OS: Debian 9
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: video dot ice dot power at seznam dot cz
New email:
PHP Version: OS:

 

 [2019-09-19 07:41 UTC] video dot ice dot power at seznam dot cz
Description:
------------
Shutdown functions are not called when exit is called from output handler

Test script:
---------------
<?php

// capture any unexpected output and exit execution
ob_start(function($buffer) {
    echo 'unexpected output: ' . $buffer . "\n";
    exit;
}, 1);

// do some work on shutdown
register_shutdown_function(function() {
    ob_flush();
    ob_end_clean();
    echo 'shutting down';
});

echo 'x';

Expected result:
----------------
unexpected output: x
shutting down

Actual result:
--------------
(empty result)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-17 18:25 UTC] archon810 at gmail dot com
We've been trying to figure out why Sentry doesn't fire in AMP and arrived at the same conclusion - lack of the register_shutdown_function call when in ob_, which is used by AMP.

Please see https://github.com/getsentry/sentry-php/issues/927 and https://github.com/ampproject/amp-wp/issues/3825.

If any PHP core devs would chime in, that'd be great.

Thank you.
 [2021-04-06 17:11 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-04-06 17:11 UTC] cmb@php.net
I cannot reproduce this; I get (PHP-7.3 and -7.4 on Windows, and
PHP-7.4 on Debian):

Fatal error: ob_flush(): Cannot use output buffering in output buffering display handlers

So, apparently, the shutdown handler is executed.  What am I
missing?
 [2021-04-06 19:21 UTC] video dot ice dot power at seznam dot cz
https://3v4l.org/ZoBJs - "shutting down" text is not printed
 [2021-04-06 21:38 UTC] cmb@php.net
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-04-06 21:38 UTC] cmb@php.net
Well, yes, for PHP 8.0, but you specified that this is about PHP
7.3.9.
 [2021-04-06 22:18 UTC] video dot ice dot power at seznam dot cz
The issue is also in PHP 7.3 and 7.4, only the result is different.

Handler of ob_start should be called without any limitation and the output should be handled once the handler ends.
 [2022-01-17 11:40 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-01-17 11:40 UTC] cmb@php.net
Closing as duplicate of <https://github.com/php/php-src/issues/7957>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC