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