I am trying to implement a Facebook-like live notifications system to notify users whenever someone adds them as friend, like their post or posts replies to their comments.
All the database and PHP part is done, but I can't figure out how to implement it like Facebook has.
Whenever someone likes/comments on your post in Facebook the light blue box appears at the bottom left corner of the screen. This happens as soon as someone hits like button or posts comment in Facebook. I would like to know what I should do to implement this.
Using YUI or any JavaScript framework I can query a database table after n seconds to check for notifications. This method is too heavy.
I was wondering if there is any server side mod or scripting can be done so that whenever there is new notification entry in my database table the server will tell that particular client. That way unnecessary request calls from client to server will be avoided completely and system can work efficiently for website with more than 50,000 users online at a time.
How can I achieve this?
You should look into COMET techniques, such as forever frame (tutorial) and long polling. That allows you to have a form of a server->client push communication.
I am really surprised nobody has mentioned PubNub and Pusher
These two (competitors) are building infrastructure which allows for realtime notifications, just like Facebook.
Facebook notification
You basically set a request up, like callng the service that asks your server/db for the notifications of that user. You may do a while loop that retries if theres no notification (maybe Thread.Sleep in between searches). Your js request will timeout, then you can call the function again in timeout. This means long polling afaik
The only way to do it is to have some sort of mechanism (e.g. Javascript) to repeatedly poll the server for updates. Doing server pushes to web browsers isn't possible.
Related
I am developing a sort of social media website. You can see someone's profile, you can rate the profile, you can submit a comment on their profile etc. So a sort of facebook thing.
All my actions are done with AJAX calls. Now I created a PHP websocket server for private chat. Now is my question what do you think about replace all the AJAX calls to calls to the websocket server? So each user action goes via websockets. Is this good or wrong? What about when 5 people clicking on the same profile at the same time, does this have any consequence to the socket server? Is the socket server able to handle all those actions mentioned above at the same time?
Need your thoughts on this, thank you.
I have an app where basically players challenge each other. At some point their challenge completes and I need to provide them (both of them - there are two players) with an update message, like 'Hey, you won and got 100500 points'. And vice versa - "Hey You looose"
I use websockets and pusher api to tackle the live updates, this works perfectly when player is "online". But what if they are not? The way to go for me looks like I can still handle the event with pusher and instead just displaying the message, I can store it to db to table challenge_notifications with fields messages and seen = 0. it's ok, but what would be the best way then to show this to the player when he comes online next time? I don't want to have ajax request on every page load checking to see if there are any unseen notifications for the user.
I probably somehow need to fetch all pending notifications only once, when they get online?
I use Laravel 5 for my backend.
There was a recent post on the Pusher blog about how to detect if a user is online or not using the Pusher HTTP API: Enabling Smart Notifications with Pusher and SendGrid.
The example uses SendGrid, but you could instead store the update to a database, send them a Push Notification, an SMS etc.
what would be the best way then to show this to the player when he comes online next time?
I guess there are two forms of "coming online":
The user is no longer on the site and has to navigate to the site. In that case as the page loads you can query the DB and serve them up any missed notifications directly (this would seem the easiest solution). Or, if it fits your app architecture, make a single AJAX request when the page loads to get any missed notifications.
If the user has gone offline due to them being mobile or having a bad network connection. In that case you can bind to the connected event using pusher.connection.bind('connected', function() {}); and then make a query to see if they've missed any notifications.
In summary: it would seem that querying the DB for any missed notifications upon normal page render (on the server) would be the simplest solution and wouldn't required much resource usage. But there are alternative mechanisms of delivering a notifications (email, SMS) if they're not online.
I want to make a chat application with php & jquery. But jquery script visible to client side and another problem is every time need to update chat display panel by calling interval methods. So my question is, is there any other way to develop a chat app like gmail chat app.
Becouze gmail chat is show presence. When user went to offline automatically shows offline status. and when user entered text into chat box, instantly shows in chat display. so i wanna make to like that application.
Please guide me....
Thanking you,
You can do this with WebSockets. There are some cool WebSockets tools out there like:
Ratchet - http://socketo.me/
Wrench - https://github.com/varspool/Wrench
phpwebsocket - https://code.google.com/p/phpwebsocket/
apache-websocket - https://github.com/disconnect/apache-websocket
Using WebSockets you can append received messages to the chat log instead of updating the whole thing like it seems you are doing.
In case you choose to (or have to) keep requesting new messages to the server, since not all hosting providers will allow WebSockets, here are some tips that you may find useful to improve your chat app:
Store the last received message id on client-side, so that when you request new messages to the server you can send it this id and it will only send you messages you didn't receive yet, thus avoiding unnecessary traffic.
On the server side, record the last time a client requested new messages, so that you can define a timeout in order to detect user disconnection.
To avoid overloading your server or client with more requests than it can handle, take into consideration the time took by the server to answer your last request when you define the interval for the next request, like this:
Client requests messages
Server replies in 100ms
Client waits 100ms before requesting again
Server replies in 200ms
Client waits 200ms before requesting again
...
In order to update the status and message real time without polling, you need to use websocket connection.
Here is a jsfiddle for building a chat using Applozic jquery chat plugin which uses websocket.
https://jsfiddle.net/devashishmamgain/L68teL67/
(function(d, m){var s, h;
s = document.createElement("script");
s.type = "text/javascript";
s.async=true;
s.src="https://apps.applozic.com/sidebox.app";
h=document.getElementsByTagName('head')[0];
h.appendChild(s);
window.applozic=m;
m.init=function(t){m._globals=t;}})(document, window.applozic || {});
window.applozic.init({userId: 'devashish', appId: 'f769902edce1e93b6d03a1d5f', desktopNotification: true, notificationIconLink: "https://www.applozic.com/resources/images/applozic_logo.gif"});
Look on Below questions..
Javascript based XMPP chatclient using strophe js - Examples and tutorials?
You can find your requirement related to chat using stropher js for XMPP protocol on this below working github code.
https://github.com/metajack/profxmpp
Look on chap :06 demo (GAB Tut).
It will satisfy all your requirement related to
one to one chat.
Roster list (Friend list),
Send friend request,
In coming request approval.
Start one to one chat etc...
and all important demo also included
Let me know you have any query in this demo. :) :)
Yes if you use PHP to fetch data from server side then you would need to poll and check for new message at a regular interval. This creates unnecessary load on the server side and proves difficult to scale because we keep polling even when there is no new message.
This problem may be solved by using a push technology like websocket instead of polling. Our product, ChatCamp uses push technology to deliver messages in real time and is highly efficient and scalable. You may use our ChatCamp JavaScript SDK to quickly create a jQuery chat application - https://chatcamp.io/blog/jquery-chat/.
What are the best approaches to build a "Craigslist Notifications" software that shoots new postings directly to my email/sms/rss?
For example, I am constantly refreshing the "Free" category waiting for new postings.
I can say anything for iPhone but on Android I would use AlarmManager to to periodically check the resource (Craigslist in your case) for updates. Once update is detected process and post to RSS or whatever.
There' s a "craigslist notifications" application for android where you can setup notifications every couple minutes for new postings based on the keywords and price parameters you set. I would look at how that application is coded since it is written in open source. :)
I'm the developer of CraigsNotifica for android. The idea is to use AlarmManager like droidin.net said.
i need to create a chat application in php+js+ajax which need to be integrated to a site, where am stuck is to create a chat window , that need to be constant while going through different pages in the site . if any one can suggest a better way i will be grateful, thanks in advance
As for the actual chat application...
Using some kind of technology to push data from the server -> your users is the best way to achieve a real-time chat application.
I would highly recommend checking out APE (Ajax Push Engine).
It takes care of the server-side stuff and allows you to seamlessly transfer data from the server -> client.
As far as the chat window staying when you change pages, I can think of three options:
Put the chat in a separate frame and only change the main frame when going to a new page.
Change the page content with AJAX instead of making a full page reload.
Assuming the chat messages are being stored on the server, simply repopulate the chat with the most recent messages after the new page loads.
There are plenty of tutorials available, try one of these three that came up first from a Google search for "php chat tutorial":
http://www.tutorialized.com/tutorials/PHP/Chat-Systems/1
http://code.jenseng.com/jenChat/
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=9