Rectangle 27 1

On my old project, I always run a script every three (3) seconds. It submits the last ID of the latest message, and the script checks if there is an ID higher than the latest message ID of the current conversation, if so it will load those messages.

<div id="message-div">
    <div id="49" class="mes">User 1: What's up?</div>
    <div id="50" class="mes">User 2: Okay. How about you?</div>
    <div id="51" class="mes">User 1: Pretty fine.</div>
</div>

My script will run every three (3) seconds, and submit the latest ID using Ajax (with the example above which is 51). It will check if there is an ID higher than 51 and then append() it to #message-div.

Just make sure when you append a new message, it includes the ID of that message.

var new-message = '<div id="52" class="mes">User 2: That is good to hear.</div>'; /* THIS COMES FROM AN AJAX REQUEST */
$("#message-div").append(new-message);

I did not use a status column or whatsoever. What I did for the read feature is to have an extra table for storing the date and time when a user read a message.

read_id | message_id | user_id |      read_date
---------+------------+---------+---------------------
    1    |     51     |    2    | 2016-06-03 14:29:30 /* USER 2 READ MESSAGE 51 IN JUNE 3, 2016 AT 2:26 PM */
    2    |     52     |    1    | 2016-06-03 14:30:10

i have to maintain last id, and to keep check that if that incremented in table or not, if incremented then i'll show that, right ?

@Adas - yes, that is right. It will check your table in your database if there is a higher message_id, if so, it will load that/those message/s.

well i do not want read_date like column because i already using timestamp and will check time from that. But let me change my code and implement your solution, i'll definitely chose your answer.

@adas - you can have the data type of the read_date column to DATETIME or TIMESTAMP.

php - read message status by both users in chat system - Stack Overflo...

php jquery mysql chat
Rectangle 27 0

Long polling is indeed pretty disastrous for PHP. PHP is always runs with limited concurrent processes, and it will scale great as long as you optimize for handling each request as quickly as possible. Long polling and similar solutions will quickly fill up your pipe.

It could be argued that PHP is simply not the right technology for this type of stuff, with the current tools out there. If you insist on using PHP you could try ReactPHP, which is a framework for PHP quite similar to how NodeJS is built. The implication with React is also that it's expected to run as a separate deamon, and not within a webserver such as apache. I have no experience on the stability of this, and how well it scales, so you will have to do the testing yourself.

NodeJS is not hard to get into, if you know javascript well. NodeJS + socket.io make it really easy to write the chat-server and client with websockets. This would be my recommendations. When I started with this is, I had something nice up and running within several hours.

Thank you. As with many comments I've seen, NodeJS + socket.io seems the way to go, assuming I build this myself. I won't waste any more time dabbling with long polling, I'll steer clear ! Have now downloaded node and socket and will dabble. Thanks again!

jquery - PHP chat active users - Stack Overflow

php jquery mysql chat comet
Rectangle 27 0

you could always get the right tool for the job ... an XMPP compliant bit of software. for as poor as the documentation is, ejabber is pretty alright. because it follows closely the XMPP standard: http://code.google.com/p/ijab/ you can use any XMPP client. You can store all of it in an RDBMS if you like and provide similar functionalities that are offered in gmail / google talk.

Live chat with PHP and jQuery. Where to store information? Mysql or fi...

php jquery mysql chat
Rectangle 27 0

WebSockets and nodejs are insanely difficult and too comprehensive for something easy like this. A long pull is indeed a good idea (the simplest and best imo). A simple, closing request every 2 or 5 seconds doesn't cost anything either, because there's always only 1 person waiting/firing those requests. 2 people -> connect. 3 people -> 2 ppl connected and 1 waiting. etc

javascript - Random chat with php/ mysql /jQuery - Stack Overflow

php javascript jquery mysql ajax
Rectangle 27 0

Add a column for "last active." Every time the user performs some action (which may include the browser polling for more messages via AJAX, for example) you update that column to NOW(). Then your query for finding active users can be something like:

SELECT user.name FROM user
    WHERE DATE_ADD(user.last_active, INTERVAL 5 MINUTE) >= NOW();

Deleting old records from the table is fine, but is probably an optional enhancement (depending on site load).

php - How to find the users who are online - Stack Overflow

php mysql chat
Rectangle 27 0

you can easily check the active sessions if you store the sessions in the db table, please check the php manual http://in.php.net/manual/en/function.session-set-save-handler.php

php - How to find the users who are online - Stack Overflow

php mysql chat