Step by Step Guide to Installing Socket.io and Broadcasting Events with Laravel 5.1

I've decided to put together a guide to help others in setting up socket.io within their projects. I hope you find this resource useful.

A big big shout out goes to @toniperic for helping me get socket.io up and running. You can view the original article where I got some of the information from; this guide builds upon it drastically, fills in the gaps, and is brought it up to date.

Please excuse any mistakes in this walkthrough, the Markdown wasn't being parsed correctly while I wrote it. I will edit it in situ within the Laracasts Forum when I spot errors. If you feel I should elaborate anywhere or amend anything please let me know below.

~~At the time of writing this (3 Jun 2015) Laravel 5.1 hasn't been released. It is due for release on 9 Jun 2015 so it certainly isn't long to go. I thought I'd get a head start on the game and put together this guide from different sources I found online.~~

Trying it out

Keep refreshing the first window and you should see the second page's content increment.

You're all done!

(I had to make this point (a) to make it an even 20! and (b) to kindly ask for your feedback. If follow this guide and you get stuck anywhere, or it doesn't make sense, or anything really, please let me know.)

This is such a good post. @mstnorris I really respect your posts. They add value and content and I don't think I've ever seen you ask for anyone's help, you only ever contribute. Many thanks!

I'd be interested to know how people use this with Laravel Forge. I.e. Install socket.io and get it up and running. Particularly with a horizontally scalled node which houses the socket.io server that is linked to the main server.

@olimorris thank you so much for those very kind words. I think I ask more questions than you realise but I hope I do it in a way that it helps others too which is why I created the Guidelines for posting on Laracasts.com. It is how I like to see questions being asked as it is easier to understand so of course that is how I approach it when I ask questions of my own.

Well as I am running a Digital Ocean server provisioned with Forge I shall let you know. I plan on tackling that either tomorrow or early part of next week and I will document my process then too.

@lstables I chose to go with socket.io as Pusher starts charging when you go over 20 connections. A connection is any open channel to Pusher; meaning that as soon as more than 20 people (each have a browser open to your app) are on the site simultaneously then you will have to start paying. Or if 10 people each have two browser windows open, then you'll go above 20 connections!!!.

Also, there may be latency issues with the HTTP requests while accessing Pusher whereas it is instant with socket.io. It is minimal JavaScript and in all honesty very easy to set up (following the guide above). I'm not too familiar with JavaScript and I got through it with some help and other resources.

@mstnorris yes going to follow your guide through, just thought I'd share a resource should anyone want to use Pusher too, how about setting this up on Forge is that the same as on Homestead ? Just SSH in and install required libs?