I'm building a web application where users can sign up, add twitters feeds that they want to follow and their stream will update as the feeds they're following receive new posts.
My go to platform is Laravel. However, I can't think of the best way to implement the live update aspect of the site.
I would use an AJAX function that is called periodically (every 30 seconds for example) but as the number of users increases this method as it's drawbacks.
I've looked into HTML5 Server Side Events but IE isn't supported unfortunately.
What would be the best way to implement this functionality within a Laravel App?
Thanks,
Nick
You have two options :
You can read more about websockets here : https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
And you can read more about long polling here : https://www.quora.com/Why-would-HTTP-long-polling-be-used-instead-of-HTTP-Streaming-to-achieve-real-time-push-notifications
In short :
websockets run on a different port than your usual app, so accessing all your assets can be a bit strange(depending on your system architecture).
Long polling is a very long http request that can last up to several minutes, instead of sending a request every 30 seconds, you send it every time the server returns a response. this means that if the server took 5 minutes to return a response, you're only sending a request once per 5 minutes. (for example, there's no reason to alert the client that nothing changed at all, so you can sleep(30) and try again)
As a side note, Unless you need real time data, I think long polling is much easier to implement and use with a framework such as laravel.
you can use pusher or node.js for realtime.In laracast you will find a video how to do that https://laracasts.com/series/intermediate-laravel/episodes/4
I use Pusher for real time data, is extremly easy to use and exists a Laravel package.
https://pusher.com/
https://github.com/vinkla/pusher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With