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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:05:27+00:00 2026-06-12T23:05:27+00:00

I want to build a chat, based on JavaScript (jQuery will be used for

  • 0

I want to build a chat, based on JavaScript (jQuery will be used for AJAX) and PHP.

I’ve heard a good way of doing this is to use long-polling.

I do understand the idea, but I don’t know how to implement it on the server side.

An infinite loop sounds like a bad idea.

  • 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-12T23:05:28+00:00Added an answer on June 12, 2026 at 11:05 pm

    You don’t want to create an infinite loop, but you can set a timeout. Basically loop for X second waiting for some sort of data, and if that doesn’t happen send a response to the client telling it that it needs to initiate a new request, which will have the same timeout period.

    $source; // some data source - db, etc
    $data = null; // our return data
    $timeout = 30; // timeout in seconds
    $now = time(); // start time
    
    // loop for $timeout seconds from $now until we get $data
    while((time() - $now) < $timeout) {
        // fetch $data
        $data = $source->getData();
    
        // if we got $data, break the loop
        if (!empty($data)) break;
    
        // wait 1 sec to check for new $data
        usleep(10000);
    }
    
    // if there is no $data, tell the client to re-request (arbitrary status message)
    if (empty($data)) $data = array('status'=>'no-data');
    
    // send $data response to client
    echo json_encode($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a chat system in nodeJs + MYSQL using php. It
I want build a sketch pad app on iPhone, I assume that this type
I want to build a form_tag that will allow me to post a new
I'm trying to build a site that runs without refreshes, using Jquery and PHP
I want to build a dynamic ListView (like a chat list with different layouts/bubbles).
Hai I want to build a web site containing chat. i am working with
I want to build a simple web-interface application that can send/receive chat messages to/from
i want to build a chat application which supports text messaging, group messaging, file
Possible Duplicate: Socket Thread and PyGTK i want to build a GUI chat application..
I want to build a site with support chat with thousands of users which

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.