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: 2021-04-06 21:38 UTC
From: video dot ice dot power at seznam dot cz Assigned:
Status: Open Package: *General Issues
PHP Version: 7.3.9 OS: Debian 9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Apr 22 17:01:24 2021 UTC