Last active
March 21, 2022 13:58
-
-
Save Commifreak/47dd986af690d6720cc8d75883874c93 to your computer and use it in GitHub Desktop.
PHP + Apache + mod_fcgi + EventSource SSE Working example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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