Download the PHP package pavlo-krostylov/pusher-http-php without Composer

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

Pusher Channels HTTP PHP Library

Tests Packagist Version Packagist License Packagist Downloads

PHP library for interacting with the Pusher Channels HTTP API.

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

Installation

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

Or add to composer.json:

then run composer update.

Supported platforms

Pusher Channels constructor

Use the credentials from your Pusher Channels 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 HTTPS. To use plain HTTP you can set useTLS to false:

Logging configuration

The recommended approach of logging is to use a PSR-3 compliant logger implementing Psr\Log\LoggerInterface. The Pusher object implements Psr\Log\LoggerAwareInterface, meaning you call setLogger(LoggerInterface $logger) to set the logger instance.

Custom Guzzle client

This library uses Guzzle internally to make HTTP calls. You can pass your own Guzzle instance to the Pusher constructor:

This allows you to pass in your own middleware, see the tests for an example.

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):

Asynchronous interface

Both trigger and triggerBatch have asynchronous counterparts in triggerAsync and triggerBatchAsync. These functions return Guzzle promises which can be chained with ->then:

Arrays

Arrays 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:

Fetch channel info on publish [EXPERIMENTAL]

It is possible to request for attributes about the channels that were published to with the info param:

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 users

To authenticate users on Pusher Channels on your application, you can use the authenticateUser function:

For more information see authenticating users.

Authorizing Private channels

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

For more information see authorizing users.

Authorizing Presence channels

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

For more information see authorizing users.

Webhooks

This library provides a way of verifying that webhooks you receive from Pusher are actually genuine webhooks from Pusher. It also provides a structure for storing them. A helper method called webhook enables this. Pass in the headers and body of the request, and it'll return a Webhook object with your verified events. If the library was unable to validate the signature, an exception is thrown instead.

End to end encryption

This library supports end to end encryption of your private channels. This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. You can enable this feature by following these steps:

  1. You should first set up Private channels. This involves creating an authorization endpoint on your server.

  2. Next, generate your 32 byte master encryption key, base64 encode it and store it securely. This is secret and you should never share this with anyone. Not even Pusher.

    To generate an appropriate key from a good random source, you can use the openssl command:

  3. Specify your master encryption key when creating your Pusher client:

  4. Channels where you wish to use end to end encryption should be prefixed with private-encrypted-.

  5. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the https://dashboard.pusher.com/ and seeing the scrambled ciphertext.

Important note: This will not encrypt messages on channels that are not prefixed by private-encrypted-.

Limitation: you cannot trigger a single event on a mixture of unencrypted and encrypted channels in a call to trigger, e.g.

Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.

Presence example

First set the channel authorization endpoint in your JS app when creating the Pusher object:

Next, create the following in presenceAuth.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 Channels HTTP 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 Channels HTTP 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 a list of application channels with subscription counts

The HTTP API returning the channel list does not support returning the subscription count along with each channel. Instead, you can fetch this data by iterating over each channel and making another request. Be warned: this approach consumes (number of channels + 1) messages!

Get user information from a presence channel

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

The $response is in the format:

Generic get function

Used to make GET queries against the Channels HTTP API. Handles authentication.

Response is an associative array with a result index. The contents of this index is dependent on the HTTP 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.

Running the tests

Requires phpunit.

License

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

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


All versions of pusher-http-php with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
ext-curl Version *
ext-json Version *
guzzlehttp/guzzle Version ^7.2
psr/log Version ^1.0|^2.0|^3.0
paragonie/sodium_compat Version ^1.6
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 pavlo-krostylov/pusher-http-php contains the following files

Loading the files please wait ....