Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:10:04+00:00 2026-05-31T23:10:04+00:00

i’m building in php a reservation website with a schedule. I’m looking to have

  • 0

i’m building in php a reservation website with a schedule. I’m looking to have real time updates for my users in a efficient way. I found Ajax but I dont want the client to ask the server about updates but the server to send to the client the updated schedule when somebody edited the schedule.

I found that maybe the HTML5 Server Sent Events is what I need. So I tried a simple test page that retreive update via SSE.

demo.html

<!DOCTYPE html>
<html>
<body>
<h1>SSE Output</h1>
<div id="result"></div> 
<h1>Debug Console</h1>
<div id="status"></div>   
<script>
//SSE si compatible
if(typeof(EventSource)!=="undefined")
{
    var i = 1;
    var source=new EventSource("demo_sse.php?ver=2");

    //Lorsque le serveur envoie un message
    source.onmessage=function(event)
    {
        document.getElementById("result").innerHTML+=event.data + " #" + i + "<br />";          
        i++;
    }   

    //EventListener
    source.addEventListener('message', function(e)
    {
        console.log(e.data);
        //document.getElementById("status").innerHTML+= "Message Recevied<br />";
    }, false);

    source.addEventListener('open', function(e) 
    {
        // Connection was opened.
        document.getElementById("status").innerHTML+= "Connection #" + i + " opened<br />";
    }, false);

    source.addEventListener('error', function(e)
    {
        if (e.readyState == EventSource.CLOSED)
        {
            // Connection was closed.
            document.getElementById("status").innerHTML+= "Connection closed<br />";
        }
    }, false);

    //Validation de l'origine du serveur
    if (event.origin != 'https://mydomain.com') 
    {
        alert('Looks like the Origin of the EventSource (the schedule\'s live update service) wasn\'t coming from our secure server!');
        //return;
    }
}
else
{
    document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events...";
}     

</script>    
</body>
</html>

demo_see.php

 <?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');


$ver = 2;
$time = date("H:i:s");
if ($ver != $_GET["ver"])
{
    echo "data: Page updated at: {$time}\n\n";
    flush();
}
?>

The problem is that each like 3 seconds there’s a connection opened whatever if the version is matching or not so I think it’s the client that ask the server and not the server asking the client. What I would like is to keep a open connection between the client and the server so the server can send changes when there’s any update made on the schedule.

Any tips would be appreciated!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:10:05+00:00Added an answer on May 31, 2026 at 11:10 pm

    The browser is reconnecting every 3 seconds because your server code isn’t keeping the connection open. It sends the time once then ends. Try something more like this:

    while (true) {
        echo "data: Page updated at: {$time}\n\n";
        flush();
        sleep(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.