Bug #80514 [NEW]: Output Buffer Fails on Second Run

From: Date: Mon, 14 Dec 2020 15:45:47 +0000
Subject: Bug #80514 [NEW]: Output Buffer Fails on Second Run
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231084@lists.php.net to get a copy of this message
From: folarin at engineer dot com Operating system: Ubuntu 20.04.1 LTS PHP version: 7.3.25 Package: Apache2 related Bug Type: Bug Bug description:Output Buffer Fails on Second Run 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 bug report at https://bugs.php.net/bug.php?id=80514&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80514&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80514&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80514&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80514&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80514&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80514&r=support Expected behavior: https://bugs.php.net/fix.php?id=80514&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80514&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80514&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80514&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80514&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80514&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80514&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80514&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80514&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80514&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80514&r=mysqlcfg

« previous php.bugs (#231084) next »