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

The Archive Base Latest Questions

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

Is this PhP script a legitimate approach to long polling or is this to

  • 0

Is this PhP script a legitimate approach to long polling or is this to heavy on the server?

$FoundNewContent = false;

$tokens = array();

while(!$FoundNewContent) {
    usleep(300000);
    clearstatcache();
    $SQL1 = "SELECT * FROM tokens WHERE  ID > ".$_GET['tokenID'];
    $result1 = mysql_query($SQL1);
    while($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {
        array_push($tokens, $row1);
        $FoundNewContent = true;
    }
}

// Parse XML array    

flush()

I am calling this script via Ajax.

  • 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-13T21:14:16+00:00Added an answer on June 13, 2026 at 9:14 pm

    Depends on your server setup – It should work fine as long as you don’t use session, but if there are too many connections at a time it might stall the server.

    Also I would add a time limit where it returns nothing and restarts the polling. Otherwise the script could run forever if no data is added and the server timeout is set to unlimited. I usually add a 30 sec limit.

    Something like:

    $FoundNewContent = false;
    $tokens = array();
    $time = time();
    while(!$FoundNewContent) {
      usleep(300000);
      clearstatcache();
      $SQL1 = "SELECT * FROM tokens WHERE  ID > ".$_GET['tokenID'];
      $result1 = mysql_query($SQL1);
      while($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {
        array_push($tokens, $row1);
        $FoundNewContent = true;
      }
      if($time<time()-30) break;
    }
    flush()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display an image using this php script on my server. $file
Hello I currently have this PHP Script <?php if($purchase_dates != FALSE){?> <?php foreach($purchase_dates as
I am using this PHP script to download a file: $status=stripos($_SERVER['HTTP_REFERER'],'servername'); if($status===false) { header('Location:http://xyz.com);
I am trying to use this PHP script to check extension of file while
I have this PHP-script which I'd like to keep unchanged: $display = array( 'QDATETIME',
I'm using this php script $error = false; if(isset($_POST['login'])){ $username = preg_replace('/[^A-Za-z]/', '', $_POST['username']);
I have been using this PHP script for a long time and this is
I can't understand why this PHP script gives me 500 internal server error. $query
i'm builing this php script which displays a given folder 's children folders and
Is there anyway for this PHP script to know what are the scripts or

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.