|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-01-29 14:06 UTC] mike@php.net
-Status: Open
+Status: Not a bug
[2015-01-29 14:06 UTC] mike@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 11:00:02 2025 UTC |
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.