Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7443337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:18:53+00:00 2026-05-29T11:18:53+00:00

I am trying to build a MySQL, PHP, Ajax based personal messaging system. There

  • 0

I am trying to build a MySQL, PHP, Ajax based personal messaging system.

There is one table for all messages – msghistory, which looks like that

enter image description here

And another one for users’ last message check date records – chkdate.

The system works like this:

When user signs into page, page fires Ajax autocheck. Ajax calls php in every 10 sec. PHP side checks for new messages by user id. At first checks chkdate, then checks msghistory: If there are no message after last check date then system will not notify user, else will notify about this

I think this way will load server heavily, if there are 1000s of users. I wonder if explained above way is optimal? if not, what do you think about this, which way is better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:18:55+00:00Added an answer on May 29, 2026 at 11:18 am

    Long polling is a good idea. Here’s approximately how it works (though you can vary the lengths of time used). Have your PHP script (the one the client requests) run a (semi-)infinite loop that checks for a new message in the database. If no message is found, use the sleep() function to wait for ten seconds or so before the loop goes through again. Once a message is found, send it out to the client and break out of the loop. The client can then display the message, then start a new request to the “long polling” PHP script, another ten seconds later.

    Here is a demo PHP script:
    $username=$_GET[“username”];

    <?php
    while(1) {
        $messages=mysql_query("SELECT * FROM `msghistory` WHERE `to_id`='$username'");
        if (!mysql_num_rows($messages) === 0) {
            //do whatever message processing and printout you need to do here
            break;//break out of the loop. the script terminates and returns its messages to the client
        }
    }
    ?>
    

    In the near future, we are going to see the implementation of WebSockets, which allow for real-time, push-pull communication between client and server. In many cases, though, this technology is not yet ready for use. Until then, long polling is the way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP and MySQL, I have a forum system I'm trying to build. What
I am trying to build a website with mysql and php. This is the
I'm trying to build an active page menu with PHP and MySQL and am
Using MySQL and PHP; I'm trying to build an index that contains the averages
I'm trying to build a category/subcategory class with php & MySQL. I am stuck
I'm trying to build a safe user authentication system. The code is from http://net.tutsplus.com/tutorials/php/simple-techniques-to-lock-down-your-website/
I'm trying to build a query using php and mysql, $query = select *
this is a simple question. With PHP and MySQL, I'm trying to build a
I am trying to dynamically build a table on my page through ajax, using
I am trying to build a php/mysql website. But in the past, i didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.