0

I'm attempting to build a notification system for a PHP application. Every time a booking is placed, we need a notification to appear within a specified user account type inside the application.

I'm using CodeIgniter 2 on a virtual dedicated host, so I'd have the option of requesting the installation of whatever is required to get the job done.

So far, I know that PHP has limited powers over how can trigger jQuery, in that it's limited to the web browser. I know that Node.js and Socket.io can do what I want, but how would that tie in with PHP, if at all?

I also know that a polling mechanism would be bad. I've considered a method that would send the row ID via PHP to a jQuery script within the confirmation page, which could — in theory — accomplish what I have in mind, but this would rely on the web browser of the customer, which is a bit weak.

I've spent a couple of days fumbling around this question, since I'm only just getting to grips with jQuery, while I know hardly anything about Node.js or Socket.io, or what they can and cannot do, or — as mentioned earlier — how they connect with PHP.

Any advice would be welcome.

Wayne Smallman
  • 1,690
  • 11
  • 34
  • 56
  • The easiest solution would be to simply have an ajax-call going every 10, 20 seconds that checkes for new notifications. Sockets with PHP is...hmmmm, pain. – OptimusCrime Jul 12 '13 at 11:20

2 Answers2

2

With real time push methods server pushes data to the clients(channel subscribers) whenever there is an event occurs in the server. This method is advanced than pull method like polling etc, and this will be a live communication(ie, client gets live updates from server with no time. In pull method there is a time interval between each query). Examples for real time push methods: Faye, pusher, socket.io, slanger

Most of the real time push methods are built on ruby or nodejs. So if you wish to setup your on real time server you must setup them in your server(probably ruby or nodejs) and you can communicate with that server from php using curl statements. Also there are php libraries available for these operations.

If you like to setup slanger then you can use the pusher php library itself (may be you need to modify it slightly to use with slanger). And if you like to use faye then here is a php library wrote my self: faye php wrapper

Harish Ambady
  • 12,525
  • 4
  • 29
  • 54
  • Harish, while I don't doubt your advice, I wouldn't know where to begin. Do you have any suggestions in that regard? – Wayne Smallman Jul 12 '13 at 11:49
  • You can use a real time service provided by the providers like pusher.com(or see here http://www.quora.com/What-are-alternatives-to-pusher-com) or you can setup your on real time server. Which way you would like to go? – Harish Ambady Jul 12 '13 at 11:56
  • I'd prefer my own real time server, so we have complete control. – Wayne Smallman Jul 12 '13 at 11:58
  • Then you can use one of these: slanger(an open source server implementation of the Pusher protocol - ruby), Faye(ruby and nodejs version are available), socket.io(nodejs). Follow the installation instruction from their site. – Harish Ambady Jul 12 '13 at 12:05
  • After installation you can send curl requests to your real time server url from php. – Harish Ambady Jul 12 '13 at 12:06
  • Faye makes more sense, especially if I don't have to deal with Ruby, which I also know nothing about! I think this is going to some time to figure out. – Wayne Smallman Jul 12 '13 at 12:14
0

You could store notifications in database, with corresponding timestamp. Then, use long pooling to receive messages in jQuery, that calls PHP for notifications.

Cool example was given in this anwser: How do I implement basic "Long Polling"?

Community
  • 1
  • 1
Artek Wisniewski
  • 797
  • 5
  • 13