Download the PHP package zfr/zfr-pusher without Composer

On this page you can find all versions of the php package zfr/zfr-pusher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zfr-pusher

ZfrPusher, a Pusher PHP Library

Build Status Latest Stable Version

Introduction

This is an unofficial Pusher PHP client for interacting with the REST Pusher API. Contrary to the official client, ZfrPusher is based on modern tools and with a better architecture.

Dependencies

Integration with frameworks

To make this library even more easier to use, here are various libraries:

Want to do an integration for another framework? Open an issue, and I'll open a repository for you!

Installation

We recommend you to use Composer to install ZfrPusher. Just add the following line into your composer.json file:

Then, update your dependencies by typing: php composer.phar update.

Tutorial

ZfrPusher is separated into two ways: the client object (ZfrPusher\Client\PusherClient class) which allows to execute Guzzle commands manually, and the service object (ZfrPusher\Service\PusherService class) which is a thin layer around the client that aims to simplify usage and error handling.

This is how you create a Pusher service:

Once you have access to the service, you can perform any operations.

Triggering events

To trigger an event to one or more channels, use the trigger method. First parameter can either be a single channel (string), or multiple channels (an array of strings):

trigger method also supports a fourth parameter, which is the socket id to exclude a specific socket from receiving the message (more information here):

Finally, trigger method also supports a fifth parameter which is used to make an asynchronous trigger. This means that it immediately returns to the client, without waiting for the response. By default, all trigger requests are done synchronously:

Pusher service also provides a shortcut for doing asynchronous requests with the triggerAsync method, as shown above:

Channel(s) information

You can fetch information about a single channel using the getChannelInfo method, with an optional array of information you want to retrieve (currently, Pusher API only supports user_count and subscription_count values:

You can use the method getChannelsInfo to get information about multiple channels, optionally filtered by name. Like getChannelInfo, this method accepts an optional second parameter which is an array of information to retrieve.

Presence channel users

You can retrieve all the users in a presence channel user using the getPresenceUsers method:

Authenticate private channels

To authenticate a user against a private channel, call the authenticatePrivate method, with channel name and socket id. This method returns an array whose key is 'auth' and whose value is the signed authentication string. It's up to you to encode this as a JSON string (typically done in a controller in a MVC architecture) to return it to the client:

Authenticate presence channels

To authenticate a user against a presence channel, call the authenticatePresence method, with channel name, socket id and user data. This method returns an array that contains values for auth and channel_data keys. It's up to you to encode this as a JSON string (typically done in a controller in a MVC architecture) to return it to the client:

General authentication

For ease of use, service also has a generic authenticate method that choose the right method according to channel name:

Advanced use

Error handling

When using the Pusher service, all exceptions that may occurred are handled, so that you can easily filter Pusher errors. All Pusher exceptions implement the ZfrPusher\Exception\ExceptionInterface:

Service instantiate concrete exceptions based on the error status code:

In all cases, you can find more information about the error by calling .

Usage example:

Debug applications

In the official Pusher PHP client, you can attach a logger directly to the client through a set_logger method. While simple, this was a bad way of doing it as it was hard-coded into the client (and your logger had to have a log method, so your own logger may not have it). Furthermore, the places where logging occurred were hardcoded also.

Instead, ZfrPusher client takes advantage of an event manager to do this. For instance, let's say we want to log every URL BEFORE the request is sent. Let's first create a subscriber. A subscriber implements the interface Symfony\Component\EventDispatcher\EventSubscriberInterface. In the getSubscribedEvents method, we attach a listener for the event request.before_send (you can find a complete list of available hooks here):

Next, we need to attach the subscriber to the client:

And voilà, now all the URL will be logged.

Directly use the client

While the Pusher service is convenient, you may want to directly use the Pusher client instead, so that you can have better control of how requests are sent. You can do this:

When using the client directly, the exceptions thrown when errors occurred are Guzzle exceptions, not Pusher exceptions. Therefore it is harder to filter Pusher only exceptions. If you want this feature, please use the service instead, or write your own wrapper around the Pusher client.


All versions of zfr-pusher with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
guzzle/guzzle Version ~3.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zfr/zfr-pusher contains the following files

Loading the files please wait ....