How to disable output buffering in PHP
If you are still confused regarding output buffering then check here
"Output buffering is a mechanism in which instead of sending a response immediately to browser we buffer it somewhere so that we can send it at once when whole content is ready."
Step 1
cat /etc/php74rc/php.ini | grep output_buffering
; output_buffering
;output_buffering = 4096
; performance, enable output_buffering in addition.
Step 2
service php74rc-fpm restart
Step 3
location ~ .php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_pass unix:/var/run/notboda-forresthatfield-com.sock;
fastcgi_buffer_size 1k;
fastcgi_buffers 128 1k; # up to 1k + 128 * 1k
fastcgi_max_temp_file_size 0;
gzip off;
}
Verification
To verify that output buffering has been successfully disabled, you can use the following code snippet:
<?php
echo 'Testing output buffering...';
flush(); // Flush the output buffer
ob_end_flush(); // Disable output buffering
echo 'Output buffering is disabled!';
?>
When you run this code, you should see the output "Testing output buffering...Output buffering is disabled!" displayed immediately without any delay. This indicates that output buffering has been disabled and the output is sent directly to the browser as it is generated.
Remember to remove or comment out this verification code once you have confirmed that output buffering is disabled, as it is only intended for testing purposes.
Comments
Post a Comment