We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,970 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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
dan_code_guru
Light Poster
27 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

@dan_code_guru

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:

https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events

LastMitch
Industrious Poster
4,146 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45

Any pointers as to what it is?

dan_code_guru
Light Poster
27 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0612 seconds using 2.67MB