Output Buffering - Please Help


  • | 781 points

    Hi all, been using laragon for a long time now.

    But today I have had to write a script which is quite a large one in terms of what its doing its looping through many rows from a database doing comparisons moving data around, deleting data etc etc.

    The script takes a couple minutes to run and I really need to see it outputting as it goes, I have done this on my personal server in the past and had many hours of pulling hair over having to remove all the forms of output buffering on my server to watch the task as it goes on my server the main issue was linked to nigix running but its not on the version of laragon I have.

    I have tried many things now like the standard:

    flush(); after echo
    ob_implicit_flush(); at the start
    I have checked all the config files to make sure all the buffering is disabled which it is.

    So I can't understand why the test code at the start of my script will only output after its all been completed.

    Test code:

    <?php
    ob_implicit_flush();
    
    logit('Start');
    
    for($i = 0; $i <= 1000; $i++){
    	logit('Count: '.$i);
    	usleep(10000);
    }
    
    function logit($str){
    	echo $str.'<br>';
    	flush();
    }
    

    Please please help I really need to see the script output as it runs and it would be very handy for other things I do.


  • administrators
    | 55244 points

    @sc89: What's the HTTP server you are using? (Nginx, Apache)
    If you want to see Output Buffering, use Laragon version with Apache (mod_php)


  • | 781 points

    Version 1.0.1 151223 php-5.6.16

    If that helps?


  • administrators
    | 55244 points

    Hmm, it's very old.
    You can try version 2.1.0, the Lite + Apache
    Download here:
    https://laragon.org/download.html


  • | 781 points

    Regards updating can I just install this over the top of my existing data including databases etc?


  • administrators
    | 55244 points

    For theory, it's fine but for safety, you can install on other folder (C:\laragon210 for example) and test first. Then backup your current Laragon, then overwrite it with the new one.


  • | 781 points

    Still buffering output on the latest version any ideas?

    Are you able to test my php code locally or provide code you know wont be effected by output buffering if its something I am doing?

    Using the Apache - Lite version, clean install with the same code I posted.


  • administrators
    | 55244 points

    @sc89: I'll check your code. Will keep you posted.


  • | 781 points

    Thanks, I am double checking everything and reading through post after post regarding disabling it and so far nothing seems to do it.

    Tried this in IE, Firefox, Chrome thinking it might somehow be browser level but it doesn't help.

    EDIT:

    Not sure if this helps narrow down my issue but running the file in command prompt like: php./output.php will correctly output everything as expected so will this point to apache itself being the issue?


  • administrators
    | 55244 points

    @sc89:
    This should work:

    <?php
    ob_end_flush();
    ob_implicit_flush();
    
    logit('Start');
    
    for($i = 0; $i <= 1000; $i++){
        logit('Count: '.$i);
        usleep(10000);
    }
    
    function logit($str){
        echo $str.'<br>';
    }
    

    Call ob_end_flush() first and as you called ob_implicit_flush(), you don't need to call flush() :)


  • | 781 points

    I had already set implicit flush to On in the php.ini.

    What browser are use using as this is still not working in Chrome for me and I just read that Firefox will need 1024kb of data before outputting anything.

    EDIT:

    Also see my line above about running direct in command prompt, which is fine its just in browser its not working


  • administrators
    | 55244 points

    I tested with Chrome and it works fine.


  • | 781 points

    Uh well I have no idea then, nothing I try works, I have no idea why apache is still buffering things.

    Thanks for helping but I guess I will just run PHP scripts like this in command prompt as eliminating apache is the only way this works on my machine.

    EDIT:

    Just realised I will have to output all of this to a text file or somthing now as well because command prompt wont keep the full output in the window meaning I can't look back at anything. Oh its one of those days.


  • administrators
    | 55244 points

    If you use Laragon Full, run this in Terminal

    tail -f your-text-file
    

    You can see what is going on, just a suggestion :)


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.