1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Progressive Output

Discussion in 'PHP' started by Fracisc, Feb 4, 2013.

  1. #1
    I have this code:

    for ($i = 0; $i <= 31; $i++) {
    echo $i;
    @flush(); @ob_flush(); sleep(1);
     
    }
    
    PHP:
    I cannot manage to output each number, one by one, not all at once?

    Thanks!
     
    Fracisc, Feb 4, 2013 IP
  2. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #2
    Try this:


    <?php
    header( 'Content-type: text/html; charset=utf-8' );
    ob_start();
    for ($i = 0; $i <= 10; $i++) {
    echo $i . "<br />";
    flush();
    ob_flush();
    sleep(1);
    }
    ob_end_flush();
    ?>
     
    ArMouR, Feb 4, 2013 IP
  3. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #3
    If it still does not work, add the following to your .htaccess file:
    php_value output_buffering "0"
     
    ArMouR, Feb 4, 2013 IP
  4. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #4
    Not working. It displays the result all at once.

    Adding php_value output_buffering "0" results in a 500 error.
     
    Fracisc, Feb 4, 2013 IP
  5. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #5
    Have you also tried to add the value in .htaccess file as mentioned above? It works on my side
     
    ArMouR, Feb 4, 2013 IP
  6. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #6
    Adding php_value output_buffering "0" results in a 500 error.
     
    Fracisc, Feb 4, 2013 IP
  7. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #7
    ArMouR, Feb 4, 2013 IP
  8. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #8
    Woah, that is indeed strange, okay remove that line to restore original config.
     
    ArMouR, Feb 4, 2013 IP
  9. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #9
    ArMouR, Feb 4, 2013 IP
  10. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #10
    I've tested them all. Now I read again to make sure I really tested all. Still, nothing seems to work.
     
    Fracisc, Feb 4, 2013 IP
  11. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #11
    If you're using cPanel, you might want to find out how to define variables via your php.ini. Also I read you might need to disable gzip compression. That's the best I can do from this side to help you. Hope you get through with it
     
    ArMouR, Feb 4, 2013 IP
  12. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #12
    In php.ini I have
    output_buffering = Off
    zlib.output_compression = Off
    implicit_flush = Off

    In php file I have
    header( 'Content-type: text/html; charset=utf-8' );
    echo 'Begin ...<br />';
    for( $i = 0 ; $i < 10 ; $i++ )
    {
        echo $i . '<br />';
    ob_flush();
    flush();
    ob_flush();
        sleep(1);
    }
    echo 'End ...<br />';
    PHP:
    Still not working..
     
    Fracisc, Feb 4, 2013 IP
  13. ArMouR

    ArMouR Well-Known Member

    Messages:
    161
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #13
    Did you see the ob_start(); function I added to mine?
     
    ArMouR, Feb 4, 2013 IP
  14. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #14
    Fracisc, Feb 4, 2013 IP