Answer the question
In order to leave comments, you need to log in
How to display information to the user in an infinite loop?
When loading the page, I establish a connection to the server via sse, then I need the server to send data every second.
I made an endless loop in php and everything seems to be working, the server is bombarding the user with data, but as soon as I add sleep (1) there, the page starts loading forever.
JS
var eventSource = new EventSource("/php/server.php");
eventSource.onopen = function(e){
alert('Соединение открыто');
}
eventSource.onerror = function(e){
alert('Соединиение закрыто');
}
eventSource.onmessage = function(e) {
alert(e.data);
};
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
set_time_limit(0);
while(1){
ob_start();
echo "data: сервер работает\n\n";
ob_end_flush();
}
?>
Answer the question
In order to leave comments, you need to log in
Data dependent.
If there are hints of a data model , use a DB. I love Realm (the goodies are CloudKit out of the box and a lot more).
If you save flags (passed the tutorial/not), use UserDefaults . You can set up synchronization between devices.
The value is set in one line:
If static data , create a JSON file.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question