0

I am using laravel 4 to build an app that holds information the admin puts in, and the information is displayed onto another screen in another building. For example, Admin puts in new orders and new customers, and the production needs to see the current orders. I am at first I was trying to use.

setInterval() or setTimeout()

on the production side of the screen. IT Works!! however, I do not find it very beneficial to having a server constantly refreshing. I have messed around with some socket programming, at least what I understood. Although, I feel as though I am looking and researching in the wrong place. Does any one know how I can implement a live real-time app that pushes new data straight to the view. For example. When the Admin puts an order in.... this fires and event. the event pushes the new database content to any one viewing the specific view? (with out the viewer having to refresh the page.)

How is this possible? Because I feel lost!!

  • Also note: that this will be running on the companies server, if it helps using local machines.

I am using laravel 4 + MAMP + bootstrap

user3095721
  • 51
  • 1
  • 5
  • WebSockets should be exactly what you need when you are trying to build a bidirection communication between client and server. So you'll need some PHP socket library on the serverside and a JavaScript library for the client side. – Quasdunk Dec 12 '13 at 14:48
  • See http://stackoverflow.com/questions/12216787/php-application-websocket-based-notifications-over-socket-io – Manuel Pedrera Dec 12 '13 at 15:04
  • @Quasdunk I found a package for laravel called brain-socket. Im not quite sure if this is the right library. It is a laravel implementation of Ratchet. However, are you saying I need a socket library for both php and javascript? – user3095721 Dec 12 '13 at 15:05
  • @user3095721 Yep, BrainSocket looks quite nice. As soon as something happens in your application (e. g. a new order appears), you can fire an event which is then handled by BrainSocket. So you send some data out on an open socket. On the other side, the client, you need do receive the data on the socket and then put it on the screen. So you need JavaScript on the client-side to 1. receive the data (with a WebSockets library) and 2. manipulate the DOM. It's pretty much like Ajax and the way you are doing it now, just that you don't check for data by calling a URL but by listening on a socket. – Quasdunk Dec 12 '13 at 19:26
  • @user3095721 I just saw that there is also a JavaScript implementation of BrainSocket, so the both should work together well: https://github.com/BrainBoxLabs/brain-socket-js – Quasdunk Dec 12 '13 at 19:40

1 Answers1

0

After spending several hours trying to implement different methods, I finally came across this. It took me about 10 minutes, and it is probably the coolest and most simple way I could find http://www.volkomenjuist.nl/blog/2013/10/20/laravel-4-and-nodejsredis-pubsub-realtime-notifications/

user3095721
  • 51
  • 1
  • 5