Server Sent events being sent when there is no need
Hi i am working on a server sent event script to be sent when the user has logged out, but in the network tab the server sent pages are being sent every couple of seconds with no data.
Client-Side script
var source=new EventSource("include/updates.php");
source.addEventListener('logout',function(event){
$("#notificationsContainer").append(event.data + "<br />");
source.close();
},false);
Server-side script
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
if(!isset($_SESSION))
session_start();
if(!isset($_SESSION['id']))
{
$time = date('r');
echo "event: logout\n";
echo "data: user logged out at {$time}\n\n";
flush();
}
Thanks for your time,
2
Contributors
2
Replies
1 Day
Discussion Span
7 Months Ago
Last Updated
3
Views
Related Article:How to creaye a PHP Email sent IF APPROVED script?
is a solved PHP discussion thread by drewpark88 that has 5 replies, was last updated 3 months ago and has been tagged with the keywords: php.
Hi i am working on a server sent event script to be sent when the user has logged out, but in the network tab the server sent pages are being sent every couple of seconds with no data.
You are missing something from your php code! Read this and adjusted to it: