I'm building a web chat app using session to keep the time the app last polled so that the server can determine whether messages exist between the current polling time and last polling time. It works well however, there are few instances whereby the messages sent from client A is not received by client B or the same message is produced twice on client B. Of course, the messages are not lost, always stored in the db after they are sent.

I'm wondering, is this related to my usage of session storage whereby the last and current polling time of both clients are always different(due to session data not being accessible by other user/client)? Or should I change to cache storage so that the last and current polling time of both clients to the server are always the same?

p.s. I'm using Apache server and MySQL though with AJAX setTimeout() function to poll the server at regular intervals.

1 Answer 1


It sounds like there is a poll happening about the same time as message is submitted. If that is the case a subsequent poll will not get a message added very close but after the poll. Have you tried adding some wiggle room to the polltime? Instead of getting messages after last poll get messages after last poll -1 second then give the polling client some logic to trim messages it already received? What are you using to track submission/poll time, how precise is it?

Also you if your messages are being given a auto-incrementing primary key instead of passing back the last poll time you may want to give it the last message key. There is no precision gap in consistently incrementing whole numbers.

  • 2
    Your second paragraph is the correct answer.
    – user22815
    Dec 14, 2014 at 4:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.