D
D
Danil Razumkov2017-11-18 15:38:34
Swift
Danil Razumkov, 2017-11-18 15:38:34

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
<?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

3 answer(s)
I
Ivan Vorobei, 2019-08-28
@ivanvorobei

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.

B
briahas, 2019-08-28
@briahas

look towards UserDefaults

A
Aleksandr Govorukhin, 2019-09-09
@SnapSh0t

core data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question