im trying to use Server Sent Events with PHP but not working. I tried at my web host provider (Cent OS 6 - Apache - PHP 7.3) and in virtual box with default configs (Cent OS 8 - Apache - PHP 7.3).
The webserver waiting for php output and buffering the output. I can't turn off with .htaccess.
Here is the code:

Code: Select all

<?php
date_default_timezone_set("America/New_York");
header("Cache-Control: no-cache");
header("Content-Type: text/event-stream");
$counter = rand(1, 10);
while (true) {
  // Every second, send a "ping" event.
  echo "event: ping\n";
  $curDate = date(DATE_ISO8601);
  echo 'data: {"time": "' . $curDate . '"}';
  echo "\n\n";
  // Send a simple message at random intervals.
  $counter--;
  if (!$counter) {
    echo 'data: This is a message at time ' . $curDate . "\n\n";
    $counter = rand(1, 10);
  ob_end_flush();
  flush();
  sleep(1);
Thanks for the help!
  • ↳   Website Problems
  • CentOS 8 / 8-Stream / 9-Stream
  • ↳   8 /8-Stream / 9-Stream - General Support
  • ↳   8 /8-Stream / 9-Stream - Hardware Support
  • ↳   8 /8-Stream / 9-Stream - Networking Support
  • ↳   8 /8-Stream / 9-Stream - Security Support
  • CentOS 7
  • ↳   CentOS 7 - General Support
  • ↳   CentOS 7 - Software Support
  • ↳   CentOS 7 - Hardware Support
  • ↳   CentOS 7 - Networking Support
  • ↳   CentOS 7 - Security Support
  • CentOS Legacy Versions
  • ↳   CentOS 5
  • ↳   CentOS 5 - General Support
  • ↳   CentOS 5 - Software Support
  • ↳   CentOS 5 - Hardware Support
  • ↳   CentOS 5 - Networking Support
  • ↳   CentOS 5 - Server Support
  • ↳   CentOS 5 - Security Support
  • ↳   CentOS 5 - Oracle Installation and Support
  • ↳   CentOS 5 - Miscellaneous Questions
  • ↳   CentOS 6
  • ↳   CentOS 6 - General Support
  • ↳   CentOS 6 - Software Support
  • ↳   CentOS 6 - Hardware Support
  • ↳   CentOS 6 - Networking Support
  • ↳   CentOS 6 - Security Support
  •