PHP code example of eislambey / eventsource

1. Go to this page and download the library: Download eislambey/eventsource library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eislambey / eventsource example snippets




ventSource\Event;
use EventSource\EventSource;

$es = new EventSource("http://example.com");
$messageReceived = 0;
$es->onMessage(function (Event $event) use(&$messageReceived, $es) {
    if($es === 4){
        $es->abort();
    }
    $messageReceived++;

    echo $event->data, "\n";
});

$es->connect();