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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:07:14+00:00 2026-06-15T12:07:14+00:00

I have a web application that I am trying to make more efficient by

  • 0

I have a web application that I am trying to make more efficient by reducing the number of database queries that it runs. I am inclined to implement some type of Comet style solution but my lack of experience in this department makes me wonder if a more simple solution exists.

For the sake of brevity, let’s just say that I have a database that contains a list of systems on a network and their current status (whether they are up or down). A user can sign into the web app and select which systems she is interested in monitoring. After which she can visit the monitoring page which displays the number of systems that are currently down.

As of now the count is refreshed using Ajax… every minute the client sends a request to the server which in turn runs a query against the database to get the current count and returns the result to the client. I know this in inefficient; for every client that logs in, another query is run against the database every minute. O(n) = bad!

I know that I can use some type of caching, such as memcached, but it still means there is a request for every user every minute. Better, but I still feel as if it’s not the best solution.

I envision something more like this:

  • Every minute the server runs a query to pull a count for all the systems that are currently down.
  • The server then pushes this data to the interested clients.

That way it doesn’t matter how many users are logged in and watching the monitoring page, the server only ever runs one query per minute. O(1) = good! The problem is that even after all of the research I’ve done I can’t quite figure out how to implement this. To be honest I don’t completely understand what it is that I am looking for, so that makes it very difficult to research a solution. So I am hoping that more enlightened developers can lead me in the right direction.

  • 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-15T12:07:15+00:00Added an answer on June 15, 2026 at 12:07 pm

    The solution to this issue can easily be solved with an app called Pusher, which is a hosted publish/subscribe API. In a nut shell, Pusher provides two libraries, one for the client (the subscriber) and one for the server (the publisher).

    The publisher can be a single script on your server (there are quite a few languages available) set to run at whatever interval you desire. Each time it runs it will connect to a channel and publish to it whatever data it generates. The client is created via a bit of JavaScript in your web app, and whenever a user navigates to your page, the client subscribes to the same channel your server script is publishing to and receives the data as soon as it becomes available and then can manipulate it however you see fit.

    The server:

    #!/usr/bin/php
    <?php
    require('Pusher.php');
    
    $dbh = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
    foreach($dbh->query('SELECT hostname FROM systems WHERE status = 0') as $row) {
        $systems[] = $row['hostname'];
    }
    $pusher = new Pusher($pusher_key, $pusher_secret, $pusher_app_id);
    $pusher->trigger(
        'my-channel',
        'my-event',
        array('message' => implode('<br />', $systems))
    );
    

    The client:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Pusher Test</title>
        <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
        <script src="http://js.pusher.com/1.12/pusher.min.js" type="text/javascript"></script>
        <script type="text/javascript">
          var pusher = new Pusher(key);
          var channel = pusher.subscribe('my-channel');
          channel.bind('my-event', function(data) {
            $('#systems').html(data.message);
          });
        </script>
      </head>
      <body>
        <div id="systems"></div>
      </body
    </html>
    

    So, in this case regardless of how many clients access the page there is only one database query running, and at each interval all the subscribed clients will be updated with the new data.

    There is also an open source server implementation of the Pusher protocol written in Ruby called Slanger.

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

Sidebar

Related Questions

I have a Web Application that use Hibernate 3.0. When I restart my database
I have a web application that runs fine under IIS5 or IIS6. I just
I have a web application that runs multiple websites from one codebase. I have
I have a web application that allows users to enter search criteria and the
I have a web application that will be used on iPhones, and want to
We have a web application that is generating some 3-5 parallel threads every five
I have a web application that maintains a version flag as a ServletContext.setAttribute('flag', flagValue)
I have a web application that has a constant URL and internal state machine.
I have a web application that uses fixed css width. (1280px). With jquery, I
I have a web application that uses TONS of javascript, and as usual, there

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.