Let's say your sender.php code (one php file)
echo "event: ping\n";
$msg1="This is first user";
echo 'data: {"msg": "' . $msg1 . '"}';
echo "\n\n";
echo "event: notify\n";
$msg2="This is second user";
echo 'data: {"msg": "' . $msg2 . '"}';
echo "\n\n";
The first javascript code for the user will look like this
var evtSource = new EventSource("sender.php");
evtSource.addEventListener("ping", function(e) {
var obj = JSON.parse(e.data);
var r_msg = obj.msg;
javascript
var evtSource = new EventSource("sender.php");
evtSource.addEventListener("notify", function(e) {
var obj = JSON.parse(e.data);
var r_msg = obj.msg;
, , . , ping, , , . , .
, .