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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:20:07+00:00 2026-05-27T19:20:07+00:00

I want to implement a chat application but I don’t want to use timeout

  • 0

I want to implement a chat application but I don’t want to use timeout because it checks every few seconds. Is there any other method to do this?

  • 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-05-27T19:20:08+00:00Added an answer on May 27, 2026 at 7:20 pm

    You can use ajax to call to a php page that will hang until there is something new and then it sends that to the client, and after the ajax uses what it got, it can make another request to that page, that will hang again. This way you trade the requests to the server for server processing time. You can use usleep, and a while loop to keep the page alive, and don’t forget to set the execution time limit of page.

    EDIT 1:

    Well, I will suppose that you have a function to send data (I will call it request), and asynchronously waiting for a response, and you linked a function to execute on response. Let’s call that function listen.

    And another function send that sends the replies of user, or anything else. Both send and listen will request the same page, one with no POST or GET data (listen), and one with POST data containing the replies or other thing.

    The initial request will be done with listen, or when you want to manually start the listener, and after a response. The other one is called anytime you send something.

    What is important is the php code.

    If you are working in a linux environment you can use a lot of things like os signals, but in general we can use while, and usleep, so that we do not kill the server.

    and now:

    <?php
    
    // code for mysql
    if(isset($_POST))
    {
        mysql_query("INSERT INTO table (user,instance,date,reply) VALUES('".$_SESSION['user']."','room','etc','".mysql_real_escape_string($_POST['reply'])."')");
        $_SESSION['last_reply_id'] = mysql_insert_id();
    }
    
    while(true)
    {
        $rez = mysql_query("SELECT * FROM `table` WHERE `id` > '".$_SESSION['last_reply_id']."' ORDER BY `id` DESC");
    
        $repls = array();
    
        if(count($rez))
        {
            while($rez = mysql_fetch_array($rez))
            {
                $repls[] = $rez;
            }
            $_SESSION['last_reply_id'] = $repls[0]['id'];
            echo json_encode($repls);
            break;
        }
        else
        {
            usleep(200000);
        }
    }
    ?>
    

    Now, you first call listen, that will wait until it echoes an brake the loop, and when it does, you use the result, and then you call listen again. In case you want to send something, you use send, that must brake the previous request and make a new one, that after it writes the data will start the listener. And so on, I hope you got the idea, tell me if you want to clarify it a bit.

    And do not forget to use set_time_limit(0); at the start of the page.

    I might be a bit off, and need to review this code, but this is the main idea.

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

Sidebar

Related Questions

I'm working on some small chat application. I want to implement smilies over there
I've created a chat application. But my problem is that I don't know how
I want to implement chat feature in my android application,in this feature one user
We want to implement chat on our website so that users can communicate with
I want implement in my software solution an VBA editor but in c# 3.0.
I want to implement an automatic update system for a windows application. Right now
I want to implement a paperless filing system and was looking to use WIA
I want to implement a in-app chat view like the following pic. http://img408.imageshack.us/img408/4057/img0139.png How
I am trying to implement simple chat application using flex. In it all my
After painstakingly trying to implement TCP file transfer in my conference chat application using

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.