Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Server not displaying content even when buffer is flushed

    I upgraded to PHP 5.2.3 and Apache 2.2.4 on Windows XP. Now even if I have ob_implicit_fush(1) on and even if I follow up an echo statement with "ob_flush(); flush();" it still won't show any output not matter how much content is sent to the browser until the entire page finishes loading (and this includes pages as big as 1 MB).

    I have tried it in Firefox and Internet Explorer so I know it isn't browser related.

    Everything was working fine with the code we had before the upgrade. Could something be misconfigured?

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    In php.ini:
    output_buffering = Off
    implicit_flush = On
    zlib.output_compression = Off

    All antivirus software is off to prevent scan buffering.

    mod_gzip_on is set to "no" and mod_deflate is disabled in httpd.conf
    Last edited by bauhsoj; 08-31-2007 at 09:54 PM.

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The server was restarted after making these changes of course.

    For example, if I ran the following it should show dots immediately but instead waits the whole 60 seconds and then displays the page with the line of dots complete:
    Code:

    PHP Code:
    for ($i 0$i 60$i++) {
        echo 
    '.';
        @
    ob_flush();
        
    flush();
        
    sleep(1);

    Pages larger than a megabyte of content still won't show until the entire page is ready to load.

    This is on a development server that relies on immediate output to display progress of the background task.

    Even if I pad the output buffer before running the code above it still won't let any content show until the end:
    Code:
    PHP Code:
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
        echo 
    str_repeat(' '256);
    elseif (
    preg_match('/Apache(?:.*)Win/'$_SERVER['SERVER_SOFTWARE']))
        echo 
    str_repeat(' '2500);

    @
    ob_flush();
    flush(); 

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Web pages, web servers, and browsers are not designed to incrementally output content and have it rendered. This ties up resources on the web server and keeps a HTTP connection to the server open. Even though you might be doing this only for development purposes, you should reconsider the method and adopt a more universally functionally method, such as having your page refresh itself and display the current status of the process and/or use AJAX techniques.

    For your current problem, make sure that any settings related to .gz or gzip are disabled in php and your web server. Also, either turn off your browser "accept" setting for gzip compression and/or try a different browser.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Even though you might be doing this only for development purposes, you should reconsider the method and adopt a more universally functionally method, such as having your page refresh itself and display the current status of the process and/or use AJAX techniques.
    For the purposes of the particular PHP scripts in question that this has suddenly cropped up on we have been using them without issue in exactly this fashion for 3 years now. It would simply not be feasible in this instance to let the entire page load, especially when there is such an enormity of output to be tracked and it needs to be tracked in real time. Using AJAX is especially problematic for scripts which rely on a steady progression of output from other scripts to determine which part of information to send the script it is calling next. AJAX is only helpful for humans running browsers.

    Quote Originally Posted by CFMaBiSmAd View Post
    For your current problem, make sure that any settings related to .gz or gzip are disabled in php and your web server. Also, either turn off your browser "accept" setting for gzip compression and/or try a different browser.
    As stated, gz and gzip are turned off already and I have tested this in two different browsers.
    Last edited by bauhsoj; 09-01-2007 at 05:16 PM.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    So, did you actually set the browser settings so that they don't accept compression?

    There are other compression settings besides the ones you mentioned. Check any/all settings that relate to compression/buffering on the web server.

    Also, make sure that your actual php settings are what you think they are. Create a .php file with a phpinfo() statement in it and browse to the file to see what the actual settings are. It is possible that the php.ini file that you are making changes to is not the one that php is using (you won't believe how many times this has been the cause of settings not working problems.)

    Just because you have been doing something that worked for a number of years does not mean that that was the proper way to do it. It just means that you got away with breaking the rules up to now.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Also, make sure that your actual php settings are what you think they are. Create a .php file with a phpinfo() statement in it and browse to the file to see what the actual settings are. It is possible that the php.ini file that you are making changes to is not the one that php is using (you won't believe how many times this has been the cause of settings not working problems.)

    Just because you have been doing something that worked for a number of years does not mean that that was the proper way to do it. It just means that you got away with breaking the rules up to now.
    Yes, I have checked to make sure the settings are showing in phpinfo().

    As much as I would love to switch this over to something that doesn't use continuous browser output there appears to be no way to get around it and three years and over 70,000 lines of code later of attempting to do so has lead us to that conclusion. This is an inventory processing application that unfortunately requires a steady status report from other scripts. Attempting to use AJAX is putting that technology in the wrong place. Being able to flush the output buffer at will was added to the PHP language for a good reason.

    In any event, I seem to have found the culprit. If I run a massive loop of output then I get a server 500 error. Checking the error logs I saw the following:
    Code:
    [Sat Sep 01 12:31:33 2007] [error] [client 127.0.0.1] ModSecurity: Output filter: Response body too large (over limit of 524288, total length not known). [hostname "testserver.local"] [uri "/tests/buffer_test.php"] [unique_id "eMRtrcCoAQMAABMkPQ0AAAD4"]
    Disabling security2_module fixes the buffering problem. Whether it creates another I am not certain of yet.
    Last edited by bauhsoj; 09-01-2007 at 06:12 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •