Bug #68911 [NEW]: ob_flush() works only when producing notice

From: Date: Sun, 25 Jan 2015 17:39:14 +0000
Subject: Bug #68911 [NEW]: ob_flush() works only when producing notice
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190218@lists.php.net to get a copy of this message
From: david at davidsteinsland dot net Operating system: OSX Yosemite PHP version: 5.5.21 Package: Output Control Bug Type: Bug Bug description:ob_flush() works only when producing notice Description: ------------ This is a weird issue, but I'm trying to setup a basic Server Sent Event example. The goal is to flush the messages to the browser on each event. When viewing the script in my browser, or testing it using the JavaScript API, the messages seem to be flushed correctly. However, I notice that the script produces an error: Notice (8): ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush If I try to "fix" that notice by putting the shutup operator in front of ob_flush(), or putting it inside an "if (ob_get_level())" statement, the messages are now longer flushed properly. The browser and JavaScript API will wait perhaps 10 seconds before producing output. But if I let the notice be displayed, each message is flushed correctly. What is the reason behind this? Test script: --------------- <?php for ($i = 0, $j = ob_get_level(); $i < $j; $i++) { ob_end_flush(); } ob_implicit_flush(1); $stop = false; for ($i = 0; $i < 1000; ++$i) { $duration = microtime(true) - env('REQUEST_TIME_FLOAT'); echo "event: userconnect\n"; echo 'data: {"username": "bobby", "time": "02:33:48"}'; echo "\n\n"; echo "data: Here's a system message of some kind that will get used\n"; echo "data: to accomplish some task."; echo "\n\n"; echo "event: usermessage\n"; echo 'data: {"username": "bobby", "time": "02:34:11", "text": "Hi everyone."}'; echo "\n\n"; // Notice here ob_flush(); usleep($sleepTime); } Expected result: ---------------- Each message be flushed when written. Actual result: -------------- Chunk of output gets flushed at the same time, after a waiting period. If the notice gets displayed, it works. -- Edit bug report at https://bugs.php.net/bug.php?id=68911&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68911&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68911&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68911&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68911&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68911&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68911&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68911&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68911&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68911&r=support Expected behavior: https://bugs.php.net/fix.php?id=68911&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68911&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68911&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68911&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68911&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68911&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68911&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68911&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68911&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68911&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68911&r=mysqlcfg

« previous php.bugs (#190218) next »