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.

1
  • 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. Commented Jul 12, 2013 at 11:20

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

6 Comments

Harish, while I don't doubt your advice, I wouldn't know where to begin. Do you have any suggestions in that regard?
You can use a real time service provided by the providers like pusher.com(or see here quora.com/What-are-alternatives-to-pusher-com) or you can setup your on real time server. Which way you would like to go?
I'd prefer my own real time server, so we have complete control.
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.
After installation you can send curl requests to your real time server url from php.
|
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"?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.