php server gurus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brujah
    Beer Money Baron
    • Jan 2001
    • 22157

    #1

    php server gurus

    I want this to output '.' as it goes, but some output buffering is taking place and it waits to finish the whole thing before there's any output.

    Server runs Apache 2.2.9, no gzip or deflate
    php 5.2.6
    in php.ini;
    output_buffering = Off
    implicit_flush = On

    Code:
    <?php
    
    ob_implicit_flush(true);
    ob_end_flush();
    
    $i = 0;
    while($i++ < 100)
    {
    	echo '.';
    	usleep(25000);
    	if ($i%10==0) echo "\n<br />";
    }
  • borked
    Totally Borked
    • Feb 2005
    • 6284

    #2
    Code:
    <?php
    
    ob_implicit_flush(true);
    ob_end_flush();
    
    flush();
    
    $i = 0;
    while($i++ < 100)
    {
            echo '.';
            sleep(10);
            flush();
            if ($i%10==0) echo "\n<br />";
    }
    
    ?>
    I put the sleep to 10 secs cos I wasn't waiting 40+ mins to see any output ;)

    if your server doesn't do the same, compare the headers of:
    http://borkedcoder.com/flush.php

    with your server. Mine are:
    Date: Sun, 28 Feb 2010 08:09:51 GMT
    Server: Apache
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=UTF-8

    200 OK

    For coding work - hit me up on andy // borkedcoder // com
    (consider figuring out the email as test #1)



    All models are wrong, but some are useful. George E.P. Box. p202

    Comment

    • Brujah
      Beer Money Baron
      • Jan 2001
      • 22157

      #3
      Thanks for the response.
      I loaded your page, I'm still waiting for it to output anything.

      The usleep(25000) is only 0.025 seconds vs sleep(10) which is 10 seconds.

      My headers:
      HTTP/1.1 200 OK
      Date: Sun, 28 Feb 2010 08:26:04 GMT
      Server: Apache
      Content-Type: text/html

      Comment

      • Brujah
        Beer Money Baron
        • Jan 2001
        • 22157

        #4
        Ah! I just tried it in Firefox and it works there, so it must be a Mac Safari and Mac Chrome difference and not server or code related.

        Comment

        • borked
          Totally Borked
          • Feb 2005
          • 6284

          #5
          That's interesting - I didn't know the browsers handled output differently. Indeed Safari is waiting for everything before outputting.
          And yup, I changed usleep to sleep cos I though the time was too quick for a browser to capture each flush separately, but then was waiting forever, so consider that remark as me talking to myself ;)

          So, looks like nothing you can do there if it's the browser handling that's the problem.

          For coding work - hit me up on andy // borkedcoder // com
          (consider figuring out the email as test #1)



          All models are wrong, but some are useful. George E.P. Box. p202

          Comment

          • HomerSimpson
            Too lazy to set a custom title
            • Sep 2005
            • 13826

            #6
            try adding this line

            set_time_limit(0);
            Make a bank with Chaturbate - the best selling webcam program
            Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!!

            PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email:

            Comment

            • calmlikeabomb
              Confirmed User
              • May 2004
              • 1323

              #7
              http://www.ape-project.org/ - check that out.
              subarus.

              Comment

              • Naechy
                Confirmed User
                • Sep 2007
                • 6497

                #8
                answer him
                Adult SEO Labs * Buying Links * SEO
                666-874

                Comment

                • Brujah
                  Beer Money Baron
                  • Jan 2001
                  • 22157

                  #9
                  I thought about using AJAX, but just wondered why the php solution wasn't working. There's nothing wrong with the code, it's just the browser differences.

                  If you pad about 1,000 space characters with some new lines or other characters first, it starts to flush the output for the other browsers.

                  No need for extra flush() or ob_flush(), and set_time_limit isn't necessary.

                  Comment

                  Working...