How To Turn Off Output Buffering

Table of contents:

How To Turn Off Output Buffering
How To Turn Off Output Buffering

Video: How To Turn Off Output Buffering

Video: How To Turn Off Output Buffering
Video: Output buffering 2024, December
Anonim

In the process of work, php-scripts can display results as the script embedded in them is executed, or accumulate data, waiting for the complete execution of the script and the completion of the script. The choice of one of these options depends on the value assigned in the php interpreter settings to the variable responsible for buffering the data output. There are several ways to change it.

How to turn off output buffering
How to turn off output buffering

Instructions

Step 1

If you need to disable output buffering for all php scripts running on the server or on the site, the most correct way to do this is through the php.ini file. When running each script, the php language interpreter reads the settings from this configuration file, so placing the directive to disable buffering of the output of the scripts' output in it is the most optimal solution. Open the file in any text editor and use the search dialog to find the directive called output_buffering. Its value can be either an integer or a logical (On or Off) variable, so instead of the default value, enter Off or 0. If this directive is not in the configuration file, add an additional line to the end of the entries:

output_buffering = Off

Step 2

If you need to disable buffering of output for scripts of a separate folder or a group of subfolders, it is better to do this through the htaccess file. Find it in the desired directory and open it in a text editor. If there is no such file yet, create a new one. The directive that should be added is similar to the one described in the previous step, but in front of it you need to place a mark that this is one of the php settings. The entire line should look like this:

php_flag output_buffering off

Place the created htaccess file in the top folder of the directory hierarchy for which the directive is to be executed.

Step 3

To disable buffering in a single php script, use one of the built-in functions of this language. ob_get_flush () returns the current contents of the buffer, then zeroes it out and turns off output buffering. ob_end_flush () does the same, but does not return the current contents of the buffer to the variable that called it, but sends it to the output device. Ob_end_clean () simply erases the current data before turning buffering off. When using one of these functions, do not forget to turn buffering back on - this is what ob_start () is for.

Recommended: