Question

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,

Was it helpful?

Solution

You can do this with WebSockets. There are some cool WebSockets tools out there like:

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:

  1. 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.

  2. 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.

  3. 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:

    1. Client requests messages
    2. Server replies in 100ms
    3. Client waits 100ms before requesting again
    4. Server replies in 200ms
    5. Client waits 200ms before requesting again
    6. ...

OTHER TIPS

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/.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top