PHPackages                             tfleet/brain-socket - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tfleet/brain-socket

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tfleet/brain-socket
===================

Websockets for event-driven Laravel apps.

v1.0.0(12y ago)0628MITPHPPHP &gt;=5.3.0

Since Oct 31Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tfleet/brain-sockets)[ Packagist](https://packagist.org/packages/tfleet/brain-socket)[ Docs](https://github.com/BrainBoxLabs/brain-socket)[ RSS](/packages/tfleet-brain-socket/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (3)Versions (1)Used By (0)

BrainSocket.php
===============

[](#brainsocketphp)

**NOTE: BrainSocket is ideal for heavier front-end development (think single page javascript apps etc). We are currently working on integrating PUSH notifications into the next release.**

WebSockets for realtime event-driven Laravel apps.

This Laravel 4 package provides an Artisan command to setup and run a WebSocket server with [Ratchet](http://socketo.me/) inside of a Laravel app.

Lets begin by installing this package through Composer. Edit your Laravel project's `composer.json` file and add the require `brainboxlabs/brain-socket`:

```
	"require": {
		...
		"brainboxlabs/brain-socket": "v1.0.0"
	},
```

**Note:** make sure and check [packagist.org](https://packagist.org) for updated dependencies but the list above is what has been tested at the time of this writing.

Once the package and all of its dependencies have been installed we need to add the **BrainSocketServiceProvider** to our `app/config/app.php` file.

Add this line:

```
'providers' => array(
	...
	'BrainSocket\BrainSocketServiceProvider',
```

to the end of the providers array in the config file.

There is also an optional but recommended Facade you should add to the `aliases` array in the `app/config/app.php` file.

```
'aliases' => array(
	...
	'BrainSocket'     => 'BrainSocket\BrainSocketFacade',
```

Next open `terminal` and `cd` into your Laravel project directory.

run `php artisan list` and confirm you see the `brainsocket:` command in the list of commands. It should look like this:

```
Available commands:
brainsocket
	brainsocket:start
```

Once you have confirmed the list, run the following command to start the WebSocket server:

```
php artisan brainsocket:start
```

**Note:** The websocket server runs on port 8080 by default. You can change this with the optional **--port=port\_number** on the end of the artisan command.

```
php artisan brainsocket:start --port=8081
```

At this point you should see a message in the terminal saying the websocket has been started on the selected port. Terminal will be locked down / unusable at this point, to stop the WebSocket server hit `ctrl+c` in the terminal.

**Note:** Any changes to your laravel app / code while the ws server is running are not taken into account. You need to restart the ws server to see any of your changes.

Lets stop the ws server now by hitting `ctrl+c` in the terminal.

Next in your `app/` folder create a file called `events.php`

Lets add the following code to `events.php`:

```
