Bug #80514 [Com]: Output Buffer Fails on Second Run
Edit report at https://bugs.php.net/bug.php?id=80514&edit=1
ID: 80514
Comment by: folarin at engineer dot com
Reported by: folarin at engineer dot com
Summary: Output Buffer Fails on Second Run
Status: Not a bug
Type: Bug
Package: Apache2 related
Operating System: Ubuntu 20.04.1 LTS
PHP Version: 7.3.25
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
You're an angel. It works... This issue has persisted for months across multiple projects.
I'm grateful
Previous Comments:
------------------------------------------------------------------------
[2020-12-14 15:49:44] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Replace
require_once($php_file_template_path);
with
require($php_file_template_path);
------------------------------------------------------------------------
[2020-12-14 15:45:47] folarin at engineer dot com
Description:
------------
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.
Thanks
Test script:
---------------
public function getEmailBody(string $php_file_template_path){
ob_start(null,null,PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE |
PHP_OUTPUT_HANDLER_REMOVABLE);
require_once($php_file_template_path);
$xmail = ob_get_clean();
ob_end_clean();
return $xmail;
}
$msg = getEmailBody('path/to/file.php')
mail("user@example.com","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("admin@example.com","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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80514&edit=1
Thread (3 messages)