Bug #68911 [Opn->Nab]: ob_flush() works only when producing notice

From: Date: Thu, 29 Jan 2015 14:06:06 +0000
Subject: Bug #68911 [Opn->Nab]: ob_flush() works only when producing notice
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190302@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68911&edit=1 ID: 68911 Updated by: mike@php.net Reported by: david at davidsteinsland dot net Summary: ob_flush() works only when producing notice -Status: Open +Status: Not a bug Type: Bug Package: Output Control Operating System: OSX Yosemite PHP Version: 5.5.21 Block user comment: N Private report: N New Comment: You stop any output buffers with the first loop. So ob_flush() in the second produces the error. Use flush() to flush the SAPI's output stream instead. Previous Comments: ------------------------------------------------------------------------ [2015-01-25 17:39:12] david at davidsteinsland dot net 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 this bug report at https://bugs.php.net/bug.php?id=68911&edit=1

« previous php.bugs (#190302) next »