PHPackages                             leemason/polycast - 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. leemason/polycast

ActiveLibrary[API Development](/categories/api)

leemason/polycast
=================

Laravel Websocket broadcasting polyfill using ajax and mysql.

1.0.4(10y ago)102685[2 issues](https://github.com/leemason/polycast/issues)MITJavaScript

Since Oct 31Pushed 10y ago2 watchersCompare

[ Source](https://github.com/leemason/polycast)[ Packagist](https://packagist.org/packages/leemason/polycast)[ RSS](/packages/leemason-polycast/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

Polycast
--------

[](#polycast)

[![Packagist License](https://camo.githubusercontent.com/4e4b4f679fe1ac3b0c8af482af225c56abb04ca6ba575d306017f29c2195b294/68747470733a2f2f706f7365722e707567782e6f72672f6c65656d61736f6e2f706f6c79636173742f6c6963656e73652e706e67)](http://choosealicense.com/licenses/mit/)[![Latest Stable Version](https://camo.githubusercontent.com/f2e7944f774c108b11cf7541b9f03ce14c66c6abdb13ec5ba85771fe9f12d015/68747470733a2f2f706f7365722e707567782e6f72672f6c65656d61736f6e2f706f6c79636173742f76657273696f6e2e706e67)](https://packagist.org/packages/leemason/polycast)[![Total Downloads](https://camo.githubusercontent.com/221fb8075aa1be582a77fe2e6819021870d9f286107e841ad8aef738cc03495b/68747470733a2f2f706f7365722e707567782e6f72672f6c65656d61736f6e2f706f6c79636173742f642f746f74616c2e706e67)](https://packagist.org/packages/leemason/polycast)

Laravel Websocket broadcasting polyfill using ajax and mysql. Laravel 5.1 or Later

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

[](#installation)

Require this package with composer:

```
composer require leemason/polycast

```

After updating composer, add the ServiceProvider to the providers array in config/app.php

### Laravel 5.1:

[](#laravel-51)

```
LeeMason\Polycast\PolycastServiceProvider::class,
```

Add the following in your broadcasting connections array located in config/broadcasting.php

```
'polycast' => [
    'driver' => 'polycast',
    'delete_old' => 2, //this deletes old events after 2 minutes, this can be changed to leave them in the db longer if required.
]
```

Copy the package assets to your public folder with the publish command:

```
php artisan vendor:publish --tag=public --force
```

Migrate the packages database migrations (creates the polycast\_events table):

```
php artisan migrate --path=vendor/leemason/polycast/migrations
```

Usage
-----

[](#usage)

To Optionally set Polycast as your default broadcast events driver set `polycast` as the default in your config/broadcasting.php or `BROADCAST_DRIVER=polycast` in your .env file.

Once installed you create broadcastable events exactly the same as you do now (using the ShouldBroadcast trait), except you have a way to consume those events via browsers without the need for nodejs/redis or an external library to be installed/purchased.

This package doesn't aim to compete with libraries or solutions such as PRedis/SocketIO/Pusher. But what it does do is provide a working solution for situations where you can't install nodejs and run a websocket server, or where the cost of services like Pusher aren't feasible.

The package utilizes vanilla javascript timeouts and ajax requests to "simulate" a realtime experience. It does so by saving the broadcastable events in the database, via a setTimeout javascript ajax request, polls the packages receiver url and distrubutes the payloads via javascript callbacks.

To add to the simulation of realtime events each event found is parsed from the time its requested, and when the event was fired. The difference in seconds is then used to delay the callbacks firing on that specific event.

What this does is prevent every event callback dumping into the dom when the ajax request has completed, but instead fires then in sequence as if it was loading live.

To the user the only real difference to websockets is that they will be a few seconds behind (depending on the polling option provided "default 5 seconds").

I have tried to keep the javascript api similar to current socket solutions to reduce the learning curve.

Here's an example:

```
