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 8582873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:24:14+00:00 2026-06-11T21:24:14+00:00

I just started using SSE in my PHP pages. I can very easy send

  • 0

I just started using SSE in my PHP pages. I can very easy send new data with this code:

while(true) {
    if (isset($_GET["selectedName"]) && $_GET["selectedName"] != "empty") {
        echo "data:current timestamp for user ".$_GET["selectedName"]." is ".time().PHP_EOL;
        echo PHP_EOL;
        ob_flush();
        flush();
    }
    sleep(1);
}

But this means, that I’m sending data every second to the client and I have to run a loop. The string in the example is not much data. But later I want to connect to a database and pull stuff from there.

If I would pull something like a whole article (or message or what ever), I would produce a very big amount of data.

Now my question: How can I tell script to provide new data and send it to the client from another PHP script?

I created a little iOS app which uses a small API to send status updates to the server. I’d like one of the API scripts to tell the web interfaces event source script to send the new data.

And only, when I tell it to do so.
How can I achieve this?

Thanks for help, with kind regards, Julian

  • 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-06-11T21:24:15+00:00Added an answer on June 11, 2026 at 9:24 pm

    Regarding the fact I don’t have MUCH stuff to send at once (a state number from 0 to 4 and a little message string), I decided to set a variable and check if anything changed:

    static $oldStateString;
    
    while(true) {
        $result = mysql_query("SELECT * FROM st_workers");
        $currentStateString = "";
    
        while ($user = mysql_fetch_array($result)) {
            $currentStateString .= $user["stateIndex"].":--;".$user["state"].":--;".$user["humanReadableName"].":__;";
        }
    
        if ($currentStateString != $oldStateString) {
            echo "data:".$currentStateString.PHP_EOL;
            echo PHP_EOL;
            ob_flush();
            flush();
    
            $oldStateString = $currentStateString;
        }
        sleep(1);
    }
    

    BUT: I noticed that you have to start to event handler a little later, not <body onload="">. This produces errors in most browsers except Safari 6 and the current FireFox. The browser doesn’t recognize that it’s not loading anymore. So the “loading spinner” does not stop until like 5 minutes or more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using the new Eclipse 4.2 (Juno) Null Analysis. On code like
I just started using Selenium 2 tonight so this will be very basic (I
I just started using the new project type SQL Server 2008 Database. I can
I just started using SSE and wonder how I can make them more dynamic.
I just started using mysqli API for PHP. Apparently, every time an object of
I just started using java so sorry if this question's answer is obvious. I
Just started using this technique and am having strange results on the PC side.
Just started using Xcode 4.5 and I got this error in the console: Warning:
I just started using PrimeFaces and cannot figure what is wrong with my code.
I just started using Hibernate on a new project, and with my first entity,

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.