|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80514 Output Buffer Fails on Second Run
Submitted: 2020-12-14 15:45 UTC Modified: 2020-12-14 15:49 UTC
From: folarin at engineer dot com Assigned: cmb (profile)
Status: Not a bug Package: Apache2 related
PHP Version: 7.3.25 OS: Ubuntu 20.04.1 LTS
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.
Block user comment
Status: Assign to:
Bug Type:
From: folarin at engineer dot com
New email:
PHP Version: OS:


 [2020-12-14 15:45 UTC] folarin at engineer dot com
Hi all,

I'm using the output buffer to render a php file, capturing the content and sending it via email.

The process works fine for only one such cycle. That is only one file to read, and send as email to a user.

I usually have to send emails to user(confirming their actions) and to admin(to act on user actions) on the same http user request. The issue with the above is that output buffer returns an empty string for the second email file content. As a check, I did each email sending operation in isolation and they both worked - showing there was no errors with the individual files.

Output buffer successfully parses the first file, whatever that is, and returns the html string content. But on the second call to the method to parse using output buffer it returns an empty string.

php --version
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

To the best of my knowledge, toggling each of the PHP_OUTPUT_HANDLER_CLEANABLE, etc options didn't help.


Test script:
public function getEmailBody(string $php_file_template_path){
   $xmail = ob_get_clean();
   return $xmail;

$msg = getEmailBody('path/to/file.php')
mail("","My subject",$msg);

//this works for the above, but the following fails, that is $msg='', and so empty email content is reported:

$msg2 = getEmailBody('path/to/another/file.php')
mail("","My subject",$msg);

Expected result:
That both user@example and admin@example get the appropriate emails.
But in the above case, only user@example gets the email, the admin email returns an empty file read and hence empty email body


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-14 15:49 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-12-14 15:49 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at




 [2020-12-14 21:29 UTC] folarin at engineer dot com
You're an angel. It works... This issue has persisted for months across multiple projects. I'm grateful
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 14:01:29 2024 UTC