Home >Backend Development >PHP Tutorial >Other Tips - Refresh PHP Buffers to Speed Up Your Site
This article mainly introduces how to speed up your site by refreshing the PHP buffer. It is a very practical tip. Friends who need it can refer to it
Under the default configuration of the current PHP version, "Output Buffering" )" is opened. This is not the case in older versions of PHP. In older versions of PHP, every time a string is output (through the echo or print function), it will trigger an action sent to the client browser.
The introduction of "output buffering" makes this process faster and more efficient. The buffer actually opens up an area in the memory, which can be thought of as a large string in the memory. When there are characters to be output in the program, the content to be output will be appended to the buffer, which is used to replace the method of outputting directly to the browser every time in the old version of PHP. When the buffer is "refreshed", it is uniformly input to the user's browser. The following situations will cause the "refresh" operation of the buffer:
1. The PHP program is executed;
2. The size of the buffer exceeds the output_buffering value set in the php.ini configuration file;
3. flush() Or when the ob_flush() function is called.
In an actual production environment, we can speed up your site by refreshing the PHP buffer immediately after the head tag. The sample code is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Buffer flushing in action</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <?php // 这里强制刷新缓冲区 flush(); ?> <body> ...
The above has introduced the other stone - refreshing the PHP buffer to speed up your site, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.