PHPackages                             synergixe/php-beamzer - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. synergixe/php-beamzer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

synergixe/php-beamzer
=====================

This is a library that provides support for real-time feeds and notifications for PHP web applications

0.1.9(7y ago)5291MITPHPPHP &gt;=5.6.4

Since Feb 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/synergixe/php-beamzer)[ Packagist](https://packagist.org/packages/synergixe/php-beamzer)[ RSS](/packages/synergixe-php-beamzer/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (13)Versions (20)Used By (0)

PHPBeamzer
==========

[](#phpbeamzer)

[![Latest Version](https://camo.githubusercontent.com/0408ee0d1af8c5b1b11dbac531a3e3c89daa16ab0f5458b96e699d88a3810dc4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73796e6572676978652f7068702d6265616d7a65722e7376673f7374796c653d666c61742d726f756e646564)](https://github.com/synergixe/php-beamzer/releases)[![Build Status](https://camo.githubusercontent.com/23c053ff541af8f058e014fd94b4219b7371060f387d255ac5b8fc313f3337ea/68747470733a2f2f7472617669732d63692e6f72672f73796e6572676978652f7068702d6265616d7a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/synergixe/php-beamzer)[![Total Downloads](https://camo.githubusercontent.com/ca0066b3c9cfe8dc12a90b55b55f3ebc8464d1b5201b4ea8391188b05bfbd591/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73796e6572676978652f7068702d6265616d7a65722e7376673f7374796c653d666c61742d726f756e64656426636f6c6f72423d627269676874677265656e)](https://packagist.org/packages/synergixe/php-beamzer)[![License](https://camo.githubusercontent.com/92753b15d5264838f03817cd7a6a3ac7ddc5d246db09c6225d74e140bf1a3912/68747470733a2f2f706f7365722e707567782e6f72672f73796e6572676978652f7068702d6265616d7a65722f6c6963656e73652e737667)](https://packagist.org/packages/synergixe/php-beamzer)

This is a library that adds cross-browser support for real-time feeds and notifications to PHP web applications in an easy way (using Server-Sent Events (SSE) only). It currently supports **Laravel** version 5.4, 5.5, 5.6 and 5.7 only.

How to Use
----------

[](#how-to-use)

### Load Up the package from Composer

[](#load-up-the-package-from-composer)

```
		$ composer require synergixe/php-beamzer:^0.1
```

```

	"require": {
        	"synergixe/php-beamzer": "^0.1"
    	}
```

### Publish the config for the package to the Laravel config folder

[](#publish-the-config-for-the-package-to-the-laravel-config-folder)

```
php artisan vendor:publish --provider="Synergixe\Beamzer\Providers\Laravel\BeamzerServiceProvider"
```

#### This will create the package's config file called `beamzer.php` in the `config` directory of your Laravel Project. These are the contents of the published config file:

[](#this-will-create-the-packages-config-file-called-beamzerphp-in-the-config-directory-of-your-laravel-project-these-are-the-contents-of-the-published-config-file)

```
return [
	    /*
	    |--------------------------------------------------------------------------
	    | The timeout value for when Beamzer should stop trying tofetch data (milliseconds)
	    |--------------------------------------------------------------------------
	    */

	'ping' => env('BEAMZER_PING_TIMEOUT', '3000'),
	    /*
	    |--------------------------------------------------------------------------
	    | To support IE 8/9 or not when sending data back to the client.
	    |--------------------------------------------------------------------------
	    */

	'support_old_ie' => TRUE,
	    /*
	    |--------------------------------------------------------------------------
	    | Number of times before the client should retry an SSE connection.
	    |--------------------------------------------------------------------------
	    */

	'retry_limit_count' => 10,
	    /*
	    |--------------------------------------------------------------------------
	    | To use or not to use Redis.
	    |--------------------------------------------------------------------------
	    */
	'use_redis' => FALSE,
	    /*
	    |--------------------------------------------------------------------------
	    | redis publish channel name.
	    |--------------------------------------------------------------------------
	    */
	'redis_pub_channel' => 'notifications',
	    /*
	    |--------------------------------------------------------------------------
	    | The size of data sent back to the client per connection.
	    |--------------------------------------------------------------------------
	    */
	'data_chunks_size' => 5

];
```

### Create the event listener to be used with the nofication custom event using the custom command provided by the package

[](#create-the-event-listener-to-be-used-with-the-nofication-custom-event-using-the-custom-command-provided-by-the-package)

```
php artisan create:notificationfile
```

### Then create your Laravel Controllers

[](#then-create-your-laravel-controllers)

```
php artisan make:controller EventSourceController

php artisan make:controller MessageController
```

### Create the Laravel Notifications Database Table

[](#create-the-laravel-notifications-database-table)

```
php artisan notifications:table

php artisan migrate
```

### Register the route for returning your stream notifications and for create notifications

[](#register-the-route-for-returning-your-stream-notifications-and-for-create-notifications)

```
	/* In routes/web.php */

	Route::get('/users/notifications', 'EventSourceController@getNotifications');
	Route::post('/notify/subjects/{kind}', 'MessageController@fireNotificationEvent');
	Route::patch('/user/notifications/update/{nid}', 'EventSourceController@updateNotificationsAsRead');

```

### Update the app config for service provider and alias classes

[](#update-the-app-config-for-service-provider-and-alias-classes)

> If you use Laravel 5.5 and above don't bother doing this as it is included automatically

```
	/* In app/config/app.php */

	'providers' => [
	    ...
	    Synergixe\PHPBeamzer\Providers\Laravel\BeamzerServiceProvider::class
	],
	'alias' => [
	    ...
	    'Streamer' => Synergixe\PHPBeamzer\Facades\Laravel\Streamer::class
	]
```

### Setup the Controller for read notifications from the DB and return it to PHPBeamzer

[](#setup-the-controller-for-read-notifications-from-the-db-and-return-it-to-phpbeamzer)

```
	/* In app/Http/Controllers/EventSourceController.php */

	use Synergixe\PHPBeamzer\Beamzer as Beamzer;

	class EventSourceController extends Controller {

			public function __construct(){

				// code goes here...
			}

			public function pullNotificationData(Request $request, $user){

				 if(!isset($user)){
				 	return array();
				 }

				 $last_id = $request->input('lastEventId');

				 if(is_null($last_id)){

				 	return $user->unreadNotifications->take(10)->get();
				 }else{

				 	return $user->unreadNotifications->where('created_at', '>', $last_id)
									->take(10)->get();
				 }

			}

			public function deleteAllUnreadNotifications(Request $request){

				$user = \Auth::user();

				$user->unreadNotifications()->delete();

				return response()->json(array('status' => 'ok'));
			}

			public function countAllUnreadNotifications(Request $request){

				$user = \Auth::user();

				$count = $user->unreadNotifications()->groupBy('notifiable_type')->count();

				return response()->json(array('count' => $count));
			}

			/*
				The $nid variable is the notification id sent via
				AJAX (as a PATCH request) to update the status of
				the notification to "read"
			*/

			public function updateNotificationsAsRead(Request $request, $nid){

					$user = \Auth::user();

					$user->unReadNotifications()
						->where('id', $nid)
							->update(['read_at' => date('Y-m-d H:i:s')]);

					if($request->expectsJson())
						return response()->json(array('status' => 'ok'));
					else
						return response('okay', 200);

			}

			/*
				The {Beamzer} object in injected into the
				controller method as a dependency.
			*/

			public function getNotifications(Request $request, Beamzer $streamer){

			    $user = \Auth::user();

			    $response = $streamer->setup(array(
			    	'as_event' => 'activity', // event name to listen for on the client-side
				'exec_limit' => 3000, // number of milliseconds allowed for streamer to collect data and send to the browser
				'as_cors' => TRUE // For Cross Origin requests
			    ))->send(
			        array(
			           'data_source_callback' => array(&$this, 'pullNotificationData'), // function/method to return notification data as array
			           'data_source_callback_args' => array(
			                    'args' => array($request, $user) // arguments to the `data_source_callback` method/function
			            )
			        )
			    );

			    return $response;
			}
```

### Setup the EventServiceProvider to Configure Laravel events for Creating Notifications

[](#setup-the-eventserviceprovider-to-configure-laravel-events-for-creating-notifications)

```
			/* In app/Providers/EventServiceProvider */

			class EventServiceProvider extends ServiceProvider {

				/**
				 * The event listener mappings for the application.
				 *
				 * @var array
				 */
				protected $listen = [
				    'Synergixe\PHPBeamzer\Events\NotificableEvent' => [
				        'App\Listeners\NotificableEventListener'
				    ],
				];
			}
```

### Setup Controller to fire Event when something happens within your Application

[](#setup-controller-to-fire-event-when-something-happens-within-your-application)

```
			/* In app/Http/Controllers/MessageController.php */

			use Illuminate\Http\Request;
			use Synergixe\PHPBeamzer\Events\NotificableEvent as NotificableEvent;

			class MessageController extends Controller {

				public function __construct(){

					// code goes here...
				}

				public function fireNotificationEvent(Request $request, $kind) {
					$event = null;

					switch($kind){
						case "follows":
							$user = \Auth::user();
							$followee = User::where('id', '=', $request->input('followee_id'));

							$follow = $user->follows()->attach([
								$followee->id
							]);

							$event = new NotificableEvent(
								$user,
								$followee
							);
						break;
					}

					if(! is_null($event)){
						$event->setKind($kind);

						event($event);
					}
				}
			}
```

### Add the Modifier Traits (Actionable, Describable) to the Subject of your Notifications

[](#add-the-modifier-traits-actionable-describable-to-the-subject-of-your-notifications)

```
			/* In app/User.php */

			use Synergixe\PHPBeamzer\Modifiers\Actionable as Actionable;
			use Synergixe\PHPBeamzer\Modifiers\Describable as Describable;

			class User extends Eloquent {

				use Notifiable, Actionable, Describable;

				/* create the `actionsPerfomed` property for trait { Actionable } */

				protected $actionsPerfomed = array(
					"follows" => 'asked to follow you'
				);

				public function routeNotificationForMail(){

       					return $this->email_address;
    				}

				public function follows(){ // relation for all `follows`

					return $this->belongsToMany(User::class,
						    'social_network_follows',
						    'followee_id', 'follower_id', 'id', 'id', 'follows'
					)->withTimestamps();
				}

				public function followers(){ // relation for all `followers`

					return $this->belongsToMany(User::class,
						    'social_network_follows',
						    'follower_id', 'followee_id', 'id', 'id', 'followers'
					)->withTimestamps();

				}

				/* create the `makeDescription` method for trait { Describable } */

				public function makeDecription(){

					/*
						This can be used to describe the subject/object each
						time on the client-side in your notifications
						 list when rendered in HTML
					*/

					return array(
						'name' => ($this->last_name . " " . $this->first_name),
						'id' => $this->id
					);
				}
			}

```

### Modify the generated *NotificableEventListener* to include your own code in the *handle* method

[](#modify-the-generated-notificableeventlistener-to-include-your-own-code-in-the-handle-method)

```
			/*In app/Listeners/NotificableEventListener.php */

			use Synergixe\PHPBeamzer\Notifications\ActivityStreamNotification as ActivityStreamNotification;
			use Synergixe\PHPBeamzer\Events\NotificableEvent as NotificableEvent;

			class NotificableEventListener implements ShouldQueue {

				use InteractsWithQueue;

				public function __construct(){

					// code goes here...
				}

				public function handle(NotificableEvent $event){

					$event->__wakeup();

					$event_kind = $event->getKind();

					/*
						The below code assumes that the {User} model has a
						relationship called {followers} -> e.g. could be
						followers of a user on a social platform.

						So, all followers are notified using beamzers'
						custom notification {ActivityStreamNotification} with an
						action of 'asked to follow'.
					*/

					switch($event_kind){

						case "follows":

							$event->reciever->notify(
								new ActivityStreamNotification(
									$event->producer,
									$event->reciever,
									$event->timestamp,
									$event_kind
								)
							)->delay(
								\Carbon::now()->addMinutes(5);
							);
						break;
					}
				}

				public function failed(NotificableEvent $event, $exception){

			        	// code goes here...

			    	}
			}
```

### On the client-side, setup *beamzer-client JS libary* like so

[](#on-the-client-side-setup-beamzer-client-js-libary-like-so)

```

	var beam = new BeamzerClient({
               source:"http://localhost:4001/users/notifications",
               params:{
                   id:"9UmxjXuu8yjI@jws8468#3"
               },
               options:{loggingEnabled:true, interval:2500}
          });

          beam.start(function onOpen(e){
	  	console.log("SSE connection established!");
	  }, onfunction onError(e){
	  	console.log("error: ", e);
	  }, function onMessage(e){
	  	console.log("message id: ", e.lastEventId);
	  	console.log("message data: ", e.data);
	  });
          beam.on("activity", function(e){
	  	console.log("event id: ", e.lastEventId);
	  	console.log("even data: ", e.data);
	  });

```

License
-------

[](#license)

MIT

Requirement
-----------

[](#requirement)

- PHP 5.6.4 +
- Redis Server (Optional)

Support
-------

[](#support)

It isn't absolutely necessary but you can use this library with its front end component library called [beamzer-client](https://github.com/isocroft/beamzer-client/). This front end library support the follwoing browsers:

- IE 9.0+
- FF 4.0+
- Opera 10.5+
- Chrome 4.0+
- Safari 7.0+

Contributing
------------

[](#contributing)

You can contribute to this project by setting up a **DOCS** section or sending in a **PR**. report bugs and feature requests to the [issue tracker](https://github.com/synergixe/php-beamzer/issues)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.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.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~40 days

Total

19

Last Release

2612d ago

PHP version history (2 changes)0.1.1-alpha2PHP &gt;=5.4.0

0.1.1-alpha3PHP &gt;=5.6.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/860613270f89f4ce905ee254b5b5ff01bbcf8d5be259e33c02bd74df4247d888?d=identicon)[isocroft](/maintainers/isocroft)

---

Top Contributors

[![synergixe](https://avatars.githubusercontent.com/u/10416482?v=4)](https://github.com/synergixe "synergixe (324 commits)")[![isocroft](https://avatars.githubusercontent.com/u/5495952?v=4)](https://github.com/isocroft "isocroft (19 commits)")

---

Tags

event-sourcinglaravelphpserver-sent-eventsstreaming-notificationsserver sent eventsevent sourceajax long polling

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/synergixe-php-beamzer/health.svg)

```
[![Health](https://phpackages.com/badges/synergixe-php-beamzer/health.svg)](https://phpackages.com/packages/synergixe-php-beamzer)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[laravel-notification-channels/apn

Apple APN Push Notification Channel

2021.9M4](/packages/laravel-notification-channels-apn)

PHPackages © 2026

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