1. Go to this page and download the library: Download zfr/zfr-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/ */
zfr / zfr-pusher example snippets
use ZfrPusher\Client\Credentials;
use ZfrPusher\Client\PusherClient;
use ZfrPusher\Service\PusherService;
$credentials = new Credentials('application-id', 'key', 'secret');
$client = new PusherClient($credentials);
$service = new PusherService($client);
use ZfrPusher\Exception\ExceptionInterface as PusherExceptionInterface;
try {
$result = $service->getPresenceUsers('presence-foobar');
} catch (PusherExceptionInterface $e) {
// Handle exception
}
$exception->getMessage();
use ZfrPusher\Exception\ExceptionInterface as PusherExceptionInterface;
use ZfrPusher\Service\Exception\ForbiddenException;
try {
$result = $service->getPresenceUsers('presence-foobar');
} catch(ForbiddenException $e) {
// Oops, we may have reached our messages quota... Let's do something!
} catch (PusherExceptionInterface $e) {
// Any other Pusher exception...
} catch (\Exception $e) {
// Any other non-Pusher exception...
}
namespace Application\Logger;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PusherLogger implements EventSubscriberInterface
{
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
'request.before_send' => array('log', -255)
);
}
/**
* Log something
*
* @param Event $event
* @return void
*/
public function log(Event $event)
{
$request = $event['request'];
$url = $request->getUrl();
// Log the URL...
}
}
use ZfrPusher\Client\Credentials;
use ZfrPusher\Client\PusherClient;
use ZfrPusher\Service\PusherService;
$credentials = new Credentials('application-id', 'key', 'secret');
$client = new PusherClient($credentials);
$client->addSubscriber(new PusherLogger());
$service = new PusherService($client);
use ZfrPusher\Client\Credentials;
use ZfrPusher\Client\PusherClient;
$credentials = new Credentials('application-id', 'key', 'secret');
$client = new PusherClient($credentials);
// Let's do a trigger
$parameters = array(
'event' => 'my-event',
'channel' => 'my-channel',
'data' => array('key' => 'value'),
'socket_id' => '1234.1234'
);
$command = $client->getCommand('Trigger', $parameters)
->execute();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.