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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:38+00:00 2026-06-15T14:33:38+00:00

Alright, so I have made a shoutbox, I have been using it for some

  • 0

Alright, so I have made a shoutbox, I have been using it for some time, but just recently it has come to my attention that it eats at the cpu usage because of so many calls to the script, and I am wondering how I can go about fixing its performance.

Here is the js script for the shoutbox.

var current_shouts = 0;
            function $shoutid(eleid) {
                return document.getElementById(eleid);
            }
            function urlencode(u) {
                u = u.toString();
                var matches = u.match(/[\x90-\xFF]/g);
                if (matches) {
                    for (var mid = 0; mid < matches.length; mid++) {
                        var char_code = matches[mid].charCodeAt(0);
                        u = u.replace(matches[mid], '%u00' + (char_code & 0xFF).toString(16).toUpperCase());
                    }
                }
                return escape(u).replace(/\+/g, "%2B");
            }
            function shouts() {
                clearTimeout(getshout);
                var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
                xmlHttp.open("GET", "shoutbox/shouts.php?i=" + Math.random());
                xmlHttp.onreadystatechange = function() {
                    if (this.readyState == 4) {
                        if (parseInt(this.responseText) > current_shouts) {
                            getshouts();
                            current_shouts = parseInt(this.responseText);
                        }
                        getshout = setTimeout("shouts()", 1000);
                    }
                }
                xmlHttp.send(null);
            }
            function getshouts() {
                var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
                xmlHttp.open("GET", "shoutbox/getshouts.php?i=" + Math.random());
                xmlHttp.onreadystatechange = function() {
                    if (this.readyState == 4) $shoutid("shoutbox").innerHTML = this.responseText;
$shoutid("shoutbox").scrollTop = $shoutid("shoutbox").scrollHeight;
                }
                xmlHttp.send(null);
            }
            function push_shout() {
                shout();
                return false;
            }
            function shout() {
                var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
                xmlHttp.open("POST", "shoutbox/shout.php");
                var data = "user=" + urlencode($shoutid("user").value) + "&" + "shout=" + urlencode($shoutid("shout").value);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", data.length);
                xmlHttp.onreadystatechange = function() {
                    if (this.readyState == 4) {
                        if (!this.responseText) $shoutid("shout").value = "";
                        else {
                            alert(this.responseText);
                        }
                        getshouts();
                    }
                }
                xmlHttp.send(data);
                return true;
            }
            var getshout = setTimeout("shouts()", 1000);

I’m not really the brightest crayon when it comes to js so I am not really sure how to go about fixing this. The call to shouts.php is what is really eating up at my cpu.

Here is the script for shouts.php

<?php
$db = new mysqli('localhost', 'username', 'pass', 'database');

if($db->connect_errno > 0){
   die('Unable to connect to database [' . $db->connect_error . ']');
}
    $stmt = $db->query("SELECT COUNT(id) FROM shout");
    while ($shout = $stmt->fetch_assoc()) {
    echo implode($shout);
    }
session_write_close();
?>

I read up on the session locking problem so I added in the session_write_close(); but this doesn’t seem to help with my issue at all.

Any tips 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-15T14:33:39+00:00Added an answer on June 15, 2026 at 2:33 pm

    This is one of those things where tuning the code isn’t necessarily going to help a whole bunch. You’re essentially DDoS attacking your own hardware. My suggestion in the immediate future would be to bump up the javascript setTimeout frequency from 1000 to 2000 or higher. In the long run: upgrading hardware, moving to a faster/lighter storage solution (Redis is my personal favorite), both would be wise.

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

Sidebar

Related Questions

Alright so I have recently made the decision to put every string in my
Alright, so I've been doing some poking around, and I realize my problem, but
Alright i have been searching for days but there is no example of what
Alright have been working to switch to jQuery 1.7's new and improved .on() function
Alright so I have no idea how to even begin doing this But basically
Alright so I have been looking around (on SO and Google) to see if
Alright so I have been trying to get all of my separate classes (At
Alright as I have been asking the last couple days and inching closer and
Alright so I have a task, that I have to let the client try
Alright, so heres my problem: I have an application I am working with that

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.