<?php
namespace HomoChecker\View;

class ServerSentEventView implements ViewInterface
{
    public $event;

    public function __construct($event)
    {
        $this->event = $event;

        header('Content-Type: text/event-stream');

        // 2 KiB padding
        echo ":" . str_repeat(" ", 2048) . "\n";

        $this->flush();
    }

    public function render($data)
    {
        echo "event: {$this->event}\n";
        echo "data: " . json_encode($data) . "\n\n";
        $this->flush();
    }

    public function flush()
    {
        ob_end_flush();
        flush();
    }

    public function close()
    {
        echo "event: close\n";
        echo "data: end\n\n";
    }
}

<?php
namespace HomoChecker\View;

class ServerSentEventView implements ViewInterface
{
    public $event;

    public function __construct($event)
    {
        $this->event = $event;

        header('Content-Type: text/event-stream');
        flush();
    }

    public function render($data)
    {
        // 2 KiB padding
        echo ":" . str_repeat(" ", 2048) . "\n";

        echo "event: {$this->event}\n";
        echo "data: " . json_encode($data) . "\n\n";

        flush();
    }

    public function close()
    {
        echo "event: close\n";
        echo "data: end\n\n";
    }
}

--- 
+++ 
@@ -10,17 +10,23 @@
         $this->event = $event;
 
         header('Content-Type: text/event-stream');
-        flush();
+
+        // 2 KiB padding
+        echo ":" . str_repeat(" ", 2048) . "\n";
+
+        $this->flush();
     }
 
     public function render($data)
     {
-        // 2 KiB padding
-        echo ":" . str_repeat(" ", 2048) . "\n";
-
         echo "event: {$this->event}\n";
         echo "data: " . json_encode($data) . "\n\n";
+        $this->flush();
+    }
 
+    public function flush()
+    {
+        ob_end_flush();
         flush();
     }
 
Call ob_end_flush instead of sending 2 KiB padding
