Skip to content

Instantly share code, notes, and snippets.

@Commifreak
Last active March 21, 2022 13:58
Show Gist options
  • Save Commifreak/47dd986af690d6720cc8d75883874c93 to your computer and use it in GitHub Desktop.
Save Commifreak/47dd986af690d6720cc8d75883874c93 to your computer and use it in GitHub Desktop.
PHP + Apache + mod_fcgi + EventSource SSE Working example
/**
Apache configured via mod_fcgi default. No special config
**/
$padSize = ini_get('output_buffering');
header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
ob_implicit_flush(true); // flush auto
echo str_pad("data: hi1\n\n", $padSize, "\n");
sleep(1);
echo str_pad("data: hi2\n\n", $padSize, "\n");
sleep(1);
echo str_pad("data: hi3\n\n", $padSize, "\n");
sleep(1);
echo str_pad("data: hi4\n\n", $padSize, "\n");
sleep(1);
echo str_pad("data: hi5\n\n", $padSize, "\n");
sleep(1);
echo str_pad("data: ditte wars!\n\n", $padSize, "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment