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

  • Home
  • SEARCH
  • 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 6058725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:37:51+00:00 2026-05-23T08:37:51+00:00

I used flush() function in infinite loop in my php page, it echoes a

  • 0

I used flush() function in infinite loop in my php page, it echoes a text each second. when i open the page in browser it works! but when i load it via jquery ajax it doesn’t response!

php page

    <?php

if (ob_get_level() == 0) ob_start();

for ($i = 0; true/*$i<10*/; $i++){

        echo "<br> Line to show. $i";
        echo str_pad('',4096)."\n";    

        ob_flush();
        flush();
        sleep(1);

}

ob_end_flush();

?>

jquery code

$.ajax({
  url: 'res.php',

  beforeSend: function(  ) {
    $('#mydiv').html('loading...');
  },
  success: function( data ) {

      $('#mydiv').html(  data );

  }
});
  • 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-23T08:37:51+00:00Added an answer on May 23, 2026 at 8:37 am

    HTTP-Streaming can not be done simply using $.get

    insert <script> tags as following: http://ajaxpatterns.org/archive/HTTP_Streaming.php.

     <?
          while (true) {
        ?>
            <script type="text/javascript">
              $('news').innerHTML = '<?= getLatestNews() ?>';
            </script>
        <?
            flush(); // Ensure the Javascript tag is written out immediately
            sleep(10);
          }
        ?>
    

    HTTP-streaming is a very complicated hack. You should consider using long-polling instead which works in every browser. It seems there are some solutions (slide 54)

    Simple long-polling example topic:

    How do I implement basic "Long Polling"?

    This video shows how to do long-polling: http://www.screenr.com/SNH
    

    P.S: this will kill your(bad performance) server for sure. You should have a look at http://pusherapp.com which is free for small sites.

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

Sidebar

Related Questions

I'm inspecting an open source web application. There's aproblem that it used error_get_last function
i have used the follwing function to write data to user application folder private
I am trying to build a chat, basically i used the invoke function what
I have Dreamweaver CS5, and used the Insert FLV function to generate a flash
I can't seem to get the function connection_aborted to work with nginx. The code
I've got a function creating some XmlDocument: public string CreateOutputXmlString(ICollection<Field> fields) { XmlWriterSettings settings
I wanted to know how to flush the socket streams while doing socket programming
I am coding a web based exam application in PHP. The examinee has to
I am a .NET Developer, but the question I am having is not related
I wanted to know if there is any event which occurs each time a

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.