I understand Server-Sent Events but in the instructions server is in javascript and I have to be in php. In short, I figured out everything with the client, but about the server there is almost nothing but an example.

  1. For the connection to open successfully, the server must respond with the header Content-Type: text / event-stream, and then leave the connection hanging and write messages to it in a special format. - What does it mean "the server should respond with the Content-Type: text / event-stream header" I have no idea at all, but in their example the server found what you need: res.writeHead (200, {'Content-Type': 'text / event-stream ',' Cache-Control ':' no-cache '
    }); But I don `t know how to implement this on php.
  2. I will ask to give an example of sending a message. Again, in their server, eo looks like this: res.write('data: ' + ++i + '\n\n'); And I don't know about php.

    1 answer 1

    And attend to the documentation on php did not try ?

     header("Content-Type: text/event-stream"); header("Cache-Control: no-cache"); echo "data: "... 
    • yes of course I tried it turned out badly <? php echo "Content-Type: text / event-stream"; ?> - Kirpich643
    • echo "data:" ... - I do not quite understand what next the message should look like: data: Hello world! Like this ? echo "data:" Hello world !; - Kirpich643
    • @ Kirpich643, Didn't the link to the header function description bother you? - Chad
    • embarrassed but there is only about the header. - Kirpich643
    • And for some reason, the connection closes immediately. - Kirpich643