Hawaiʻi's Technology Community

I'm writing a PHP / MySQL chat room from scratch. I'm having trouble. The chat log does not display messages in real time. Each chat message is stored as a record in MySQL.

How do I make a PHP page update itself with new chat messages every time one is submitted?

Here's what I've tried:

  • Updated meta tag to refresh the PHP page -- entire page reloads even if no chat messages have been submitted. Wastes too many resources.

Here's what I'm thinking:

  • Make Javascript monitor changes to the database
  • Create a trigger in MySQL to monitor changes

Has anyone had experience with this? Can you offer some advice?


Views: 428

Replies to This Discussion

I'd go with the js, use ajax to keep the page refreshed, and trigger on submits also if you use long intervals.
1. You can do AJAX requests on intervals and check if there are new entries in chat.

2. Or the other way would be to use push from server. You can read more about this here:
Example of comet server is Meteor:
I think this tutorial video will be of help. It details the process of setting up a jQuery/AJAX function with your PHP so the entire page won't need to refresh when people are in chat mode.

(It's part 2 of a three part series that walks you through the code for creating a private messaging system from scratch, but can be easily modified for your needs fora general chat function.)
Thanks for the responses. Looks like I'll be using JQuery to update the chat log every 5 seconds.



web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service