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 8926329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:56:52+00:00 2026-06-15T07:56:52+00:00

I have a PHP script that shows multiple tables of data loaded via a

  • 0

I have a PHP script that shows multiple tables of data loaded via a JQuery AJAX call for a tournament scoring website. The tables are individual and team scores calculated in real-time.

Each table is checked once every minute for new scores and refreshed if needed. To do this, each table sends a quick ajax request to the last updated time for the scores… if the time is different than what the table currently has, the table is refreshed with new data.

My problem is that these tournaments can get quite large, with many participants, teams, divisions and scores and loading each table uses server resources. This is no problem if a handful of people are viewing the real-time stats, but once more than about 50 people are connected to this stats page, the server starts lagging heavily.

I would like to know what I can do to optimize the data, the ajax calls, or the server itself to run as efficiently as possible so that the server doesn’t top out so quickly. I’ve already combed through the MySQL calls and tried to optimize everything as much as possible, but it doesn’t seem to be enough.

Any ideas would be greatly appreciated!

  • 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-06-15T07:56:53+00:00Added an answer on June 15, 2026 at 7:56 am

    You could use a cache, for example in your architecture memcache would fit very well. Every time your server receive a request your php app try to get from cache the result, if not found execute the query.

    Now you can choose two different way:

    • easy, wait cache expire time. When the cache is expired, server miss its search and a new query is submitted. This is usually a short term cache (seconds or minutes)
    • hard, cache expire in a very far future, for example hours or even days). In this case your application refresh the cache content every time the database is updated. In this case, obviously, almost all your requests hit the cache (best performance).

    This example, is based on the easy approach and the cache key is based directly on the submitted SQL.

    global $memcache;
    $memcache = new Memcache;
    
    // Gets key / value pair into memcache ... called by mysql_query_cache()
    function getCache($key) {
        global $memcache;
        return ($memcache) ? $memcache->get($key) : false;
    }
    
    // Puts key / value pair into memcache ... called by mysql_query_cache()
    function setCache($key,$object,$timeout = 60) {
        global $memcache;
        return ($memcache) ? $memcache->set($key,$object,MEMCACHE_COMPRESSED,$timeout) : false;
    }
    
    // Caching version of mysql_query()
    function mysql_query_cache($sql,$linkIdentifier = false,$timeout = 60) {
        if (($cache = getCache(md5("mysql_query" . $sql))) !== false) {
            $cache = false;
            $r = ($linkIdentifier !== false) ? mysql_query($sql,$linkIdentifier) : mysql_query($sql);
            if (is_resource($r) && (($rows = mysql_num_rows($r)) !== 0)) {
                for ($i=0;$i<$rows;$i++) {
                    $fields = mysql_num_fields($r);
                    $row = mysql_fetch_array($r);
                    for ($j=0;$j<$fields;$j++) {
                        if ($i === 0) {
                            $columns[$j] = mysql_field_name($r,$j);
                        }
                        $cache[$i][$columns[$j]] = $row[$j];
                    }
                }
                if (!setCache(md5("mysql_query" . $sql),$cache,$timeout)) {
                    // If we get here, there isn't a memcache daemon running or responding
                }
            }
        }
        return $cache;
    }
    

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

Sidebar

Related Questions

I have problem with php script. The thing is that it shows me, that
I have a php script that inserts data from an Android app into a
I have a PHP script that creates large complex tables. I am attempting to
I have a php script on my site (users_online.php) that shows how many people
I have a PHP script that extract valid GeoJSON data from a database. Now
I have php script that creates a temporary watermark image for users that are
I have a php script that watches for the newest json file in a
I have a php script that grabs links from another website. I am storing
I have a PHP script that very much like a commenting system, but requires
I have a PHP script that opens an XML document, gets the DOM and

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.