1

I'm tried to implementing a live notification which is like the facebook newsticker and the notifications(on top). I was wondering what's the good solution to archieve this. I implemented an chat application before which I fired AJAX GET request in certain time to archieve the realtime, but it seems not good. I checked facebook using firebug, there is no GET request fired(or it is hided?)

Now here is my scenarion:

In main.php I have a live ticker and a notifications button.

In bulletion.php and User.php When I perform an add user,it will go heading to the bulletin or user.php.

How can I get informed in main.php when bulletin.php,user.php successfully created in database?

I checked this question as well before I asked. notification system in PHP/jQuery Realtime and php?

I was wonder,what's is long poling Ajax and session-based notification.How it can be archieved? I know Node.js can be good in implementing realtime, can it combine with PHP? and memcached ?

Any can provide sources to refer or example might be good.Thank you.

Community
  • 1
  • 1
Nich
  • 1,112
  • 1
  • 14
  • 29

4 Answers4

7

As a side note, PHP isn't really the best language to use when it comes to push notifications, it's really built around typical get/response kinda flows.

I use PHP for all my page stuff, but when it comes to push notifications of any sort I really like http://www.nodejs.org/ and http://socket.io/ to go with it. They're very easy to get setup, and will play well with you using php for the majority of your work, then using node to deal with push notification kinda stuff.

hexist
  • 5,151
  • 26
  • 33
  • Do you mean that we can use node.js and php at the same time? – Orvyl May 05 '13 at 23:00
  • 2
    Of course, simply run node.js on a different port (such as 8080) than apache (or whatever you're running php on). You can then connect to it with `io.connect("http://your.server.com:8080");` (presuming you're using socket.io). I then tend to expose a simple web api on my node.js server that I can call from PHP to push data to any clients applicable that are connected to node.js. – hexist May 06 '13 at 11:27
  • Sir, if its alright with you, can you give me a sample of this. Maybe a sample page in .php format who is calling/using the node.js. I am really lost/totally confused especially on the usage of node.js(how to call your functions in node.js into your html). Thank you sir. – Orvyl May 08 '13 at 07:31
  • Keep in mind node.js and php are going to be two independent processes, and so you can't just call stuff between them, nor can you call node.js function on your client side. What's I typically do is setup a web api on node.js that php "calls" (via `curl`) a RESTful API I build out on node.js, and then I connect my clients to node.js with `socket.io`. Now you have a means of talking from php (by performing a RESTful api call into node.js), which can then push data via socket.io to your clients. – hexist May 08 '13 at 12:51
  • thank you so much for the help. Plus one for your answer :) .Before ending this convo, can I ask a sample code maybe node.js querying the db then it throws it back to the html file. maybe using jsfiddle. Im sure that this can help a lot to all persons entering node.js world.It is still unclear for us how are we going to call functions of node.js for our webpages. This request is really too much but I'm still hoping for i am very desperate. Thank you again – Orvyl May 08 '13 at 14:40
  • If you're using php to generate your html, your database queries will likely happen there. If you do need to do database work in node, there are libraries to do that, google node.js + your database and you'll find plenty of examples. – hexist May 08 '13 at 16:56
1

Have you thought about using HTML5 WebSockets? Have a look at EventSockets and the kickstart project on Github.

0

I've had much success with the server-sent events standard. It's very simple and works perfectly but it's only supported in modern browsers.

Matt S
  • 14,976
  • 6
  • 57
  • 76
0

Meteor is a comet server using PHP and JavaScript to push data to browsers. It's very slick and worth a look, although it may be a little hard to setup/implement.

Edit: Quick demo here

Luke
  • 1,069
  • 18
  • 28