PHP code example of api-clients / pusher

1. Go to this page and download the library: Download api-clients/pusher 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/ */

    

api-clients / pusher example snippets


$loop = Factory::create();
$client = AsyncClient::create($loop, 'Application ID here');
// OR when you need to specify the cluster
$client = AsyncClient::create($loop, 'Application ID here', null, 'cluster-here');

$client->channel('channel_name')->subscribe(
    function (Event $event) { // Gets called for each incoming event
        echo 'Channel: ', $event->getChannel(), PHP_EOL;
        echo 'Event: ', $event->getEvent(), PHP_EOL;
        echo 'Data: ', json_encode($event->getData()), PHP_EOL;
    },
    function ($e) { // Gets called on errors
        echo (string)$e;
    },
    function () { // Gets called when the end of the stream is reached
        echo 'Done!', PHP_EOL;
    }
);

$loop->run();