Download the PHP package macromindonline/pusher-php-server without Composer

On this page you can find all versions of the php package macromindonline/pusher-php-server. 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 pusher-php-server

Pusher PHP Library

Build Status

PHP library for interacting with the Pusher HTTP API.

Register at https://pusher.com and use the application credentials within your app as shown below.

Installation

You can get the Pusher PHP library via a composer package called pusher-php-server. See https://packagist.org/packages/pusher/pusher-php-server

Or add to composer.json:

and then run composer update.

Or you can clone or download the library files.

We recommend you use composer.

This library depends on PHP modules for cURL and JSON. See cURL module installation instructions and JSON module installation instructions.

Pusher constructor

Use the credentials from your Pusher application to create a new Pusher\Pusher instance.

The fourth parameter is an $options array. The additional options are:

For example, by default calls will be made over a non-encrypted connection. To change this to make calls over HTTPS use:

For example, if you want to set custom curl options, use this:

Note: The $options parameter was introduced in version 2.2.0 of the library. Previously additional parameters could be passed for each option, but this was becoming unwieldy. However, backwards compatibility has been maintained.

Note: The host option overrides the cluster option!

Publishing/Triggering events

To trigger an event on one or more channels use the trigger function.

A single channel

Multiple channels

Batches

It's also possible to send multiple events with a single API call (max 10 events per call on multi-tenant clusters):

Arrays

Objects are automatically converted to JSON format:

The output of this will be:

Socket id

In order to avoid duplicates you can optionally specify the sender's socket id while triggering an event (https://pusher.com/docs/duplicates):

JSON format

If your data is already encoded in JSON format, you can avoid a second encoding step by setting the sixth argument true, like so:

Authenticating Private channels

To authorise your users to access private channels on Pusher, you can use the socket_auth function:

Authenticating Presence channels

Using presence channels is similar to private channels, but you can specify extra data to identify that particular user:

Presence example

First set this variable in your JS app:

Next, create the following in presence_auth.php:

Note: this assumes that you store your users in a table called users and that those users have a name column. It also assumes that you have a login mechanism that stores the user_id of the logged in user in the session.

Application State Queries

Get information about a channel

It's also possible to get information about a channel from the Pusher REST API.

For presence channels you can also query the number of distinct users currently subscribed to this channel (a single user may be subscribed many times, but will only count as one):

If you have enabled the ability to query the subscription_count (the number of connections currently subscribed to this channel) then you can query this value as follows:

Get a list of application channels

It's also possible to get a list of channels for an application from the Pusher REST API.

Get a filtered list of application channels

It's also possible to get a list of channels based on their name prefix. To do this you need to supply an $options parameter to the call. In the following example the call will return a list of all channels with a 'presence-' prefix. This is idea for fetching a list of all presence channels.

This can also be achieved using the generic pusher->get function:

Get user information from a presence channel

The $response is in the format:

Generic get function

Used to make GET queries against the Pusher REST API. Handles authentication.

Response is an associative array with a result index. The contents of this index is dependent on the REST method that was called. However, a status property to allow the HTTP status code is always present and a result property will be set if the status code indicates a successful call to the API.

Push Notifications (BETA)

Pusher now allows sending native notifications to iOS and Android devices. Check out the documentation for information on how to set up push notifications on Android and iOS. There is no additional setup required to use it with this library. It works out of the box with the same Pusher instance. All you need are the same pusher credentials.

The native notifications API is hosted at nativepush-cluster1.pusher.com and only listens on HTTPS. If you wish to provide a different host you can do:

However, note that notification_host defaults to nativepush-cluster1.pusher.com and it is the only supported endpoint.

Sending native pushes

You can send native notifications by using the notify method. The method takes two parameters:

It also takes a debug param like the trigger method to allow for debugging.

Example:

Errors

Push notification requests, once submitted to the service, are executed asynchronously. To make reporting errors easier, you can supply a webhook_url field in the body of the request. The service will call this url with a body that contains the results of the publish request.

Here's an example:

Debugging & Logging

The best way to debug your applications interaction with server is to set a logger for the library so you can see the internal workings within the library and interactions with the Pusher service.

You set up logging by passing an object with a log function to the pusher->set_logger function:

If you use the above example in code executed from the console/terminal the debug information will be output there. If you use this within a web app then the output will appear within the generated app output e.g. HTML.

Running the tests

Requires phpunit.

Framework Integrations

License

Copyright 2014, Pusher. Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php

Copyright 2010, Squeeks. Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php


All versions of pusher-php-server with dependencies

PHP Build Version
Package Version
Requires php Version ^5.4 || ^7.0
ext-curl Version *
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 macromindonline/pusher-php-server contains the following files

Loading the files please wait ....