PHPackages                             ali1/cakephp-pusher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ali1/cakephp-pusher

AbandonedArchivedCakephp-plugin[API Development](/categories/api)

ali1/cakephp-pusher
===================

A CakePHP plugin to use the Pusher API

12.1kPHP

Since Aug 20Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Ali1/Pusher)[ Packagist](https://packagist.org/packages/ali1/cakephp-pusher)[ RSS](/packages/ali1-cakephp-pusher/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

A better Pusher plugin for CakePHP 2.x
======================================

[](#a-better-pusher-plugin-for-cakephp-2x)

Massive credits to PCreations which this was forked from however it doesn't seem maintained. This app features better and easier to use security features for private channels and updated Pusher libraries.

This plugin provides a simple access to \[Pusher API\] () via \[the generic PHP Pusher library\] (). This plugin also provides a way to generate all the javascript stuff with the Helper

Installation
------------

[](#installation)

Either copy the contents of this repo to your Plugin folder or add the following to composer:

```
"ali1/cakephp-pusher": "dev-master"

```

Now load it in your bootstrap file :

```
CakePlugin::load('Pusher', array('
	'bootstrap' => true
'));

```

Add the PusherBehavior and the PusherHelper in your behaviors/helpers list :

```
//YourModel.php
public $actsAs = array('Pusher.Pusher');

//YourController.php
public $helpers = array('Pusher.Pusher');

```

Your application needs to be register on \[Pusher website\] (). You need to add the following lines to your Config/bootstrap.php file:

```
Configure::write(array(
	'Pusher' => array(
		'credentials' => array(
			'appKey' => 'YOUR_KEY',
			'appSecret' => 'YOUR_APP_SECRET',
			'appId' => 'YOUR_APP_ID'
		)
	)
));

```

How to use it
-------------

[](#how-to-use-it)

### Trigger Event

[](#trigger-event)

Trigger an event on a channel is very simple. It's a server-side flow. In your controller just do the following :

```
//Some event information
$data = array('message' => 'Something happened');

//Trigger an event named EVENT_NAME on the CHANNEL_NAME channel. You can use private and presence channel by prefixing the name by private- or presence-. See pusher docs (http://pusher.com/docs/client_api_guide/client_channels) for details
$this->YourModel->trigger(CHANNEL_NAME, EVENT_NAME, $data);

```

### Subscribe to a channel

[](#subscribe-to-a-channel)

"Receiving" a pushed event is a client-side flow, enjoy the realtime functionnality using Pusher Helper for generating javascript stuff :

```
$this->Pusher->subscribe(CHANNEL_NAME);
//The third argument receive string will be parsed as javascript.
$this->Pusher->bindEvent(CHANNEL_NAME, EVENT_NAME, "console.log('An event was triggered with message '+data.message+');");

```

### Authentication with private channels

[](#authentication-with-private-channels)

When using private channel, authentication is handled by the Pusher Controller. However you must provide a method in AppController to verify the request to access a private channel. This channel must return a boolean (true or false).

```
//Controller/AppController.php
public function _pusherCanAccessPrivateChannel($channelName, $socketId) {
	// handle user channels e.g. private-user-4324
	if (preg_match('/private-user-([0-9]+)/i', channelName, $matches)) {
		if ($matches[1] == $this->Auth->user('id')) {
			return true;
		} else {
			return false;
		}
	}
	return false; // unrecognised channel name
}

```

Example
-------

[](#example)

A very simple example could be this :

```
//Model/FooModel.php
public $actsAs = array('Pusher.Pusher');

//Controller/FooController.php
public $components = array('Auth', 'Pusher.Pusher');

public $helpers = array('Pusher.Pusher');

public function push() {
	$data = array(
		'message' => 'Something happened !',
		'triggeredBy' => $this->Auth->user('username')
	);
	$this->Foo->trigger('private-my-great-channel', 'foo_bar', $data);
}

public function receive() {

}

//View/Foo/receive.ctp
$this->Pusher->subscribe('private-my-great-channel');
$this->Pusher->bindEvent('private-my-great-channel', 'foo_bar', 'console.log("An event was triggered by "+data.triggeredBy+" with message "+data.message+);');

//Controller/AppController.php
protected function _pusherCanAccessPrivateChannel($channelName, $socketId) {
	return (bool) ($this->Auth->user()); // allow access to any channel if user logged in
}

```

Open your browser and open in one widget yourapp/foo/receive and in an another widget yourapp/foo/push. When you'll push the event you shoul see the message in your javascript console. If not, checks the ajax request to auth/ because you need to be authenticate since you're subscribing to a private channel.

Functionalities not include yet
-------------------------------

[](#functionalities-not-include-yet)

The auth for presence channel is not handled yet Get channel infos Set socket\_id to avoid duplicate event ...

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/637933d952b260bfeeaf8ec8fda92a5acf7eda16df6044fe840f782058a4c7ae?d=identicon)[Ali1](/maintainers/Ali1)

---

Top Contributors

[![PCreations](https://avatars.githubusercontent.com/u/1324175?v=4)](https://github.com/PCreations "PCreations (15 commits)")[![Ali1](https://avatars.githubusercontent.com/u/218558?v=4)](https://github.com/Ali1 "Ali1 (9 commits)")

### Embed Badge

![Health badge](/badges/ali1-cakephp-pusher/health.svg)

```
[![Health](https://phpackages.com/badges/ali1-cakephp-pusher/health.svg)](https://phpackages.com/packages/ali1-cakephp-pusher)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
