Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What conditions can cause PHP buffer flushing

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "what circumstances will cause PHP buffer refresh". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Output buffering (Output Buffering) is turned on under the default configuration of the current version of PHP. This is not the case in the old version of PHP, where each time a string is output (through the echo or print function), it triggers an action that is sent to the client browser.

The introduction of "output buffer" makes this process faster and more efficient. A buffer actually opens up an area in memory, which can be thought of as a large string in memory. When there are characters in the program to output, the output is appended to the buffer, replacing the way that the old version of PHP outputs directly to the browser every time. When the buffer is "flushed", it is uniformly entered into the user's browser. A "flush" operation of the buffer can be caused in the following cases:

1. The PHP program has been executed.

2. The size of the cache exceeds the output_buffering value set in the php.ini configuration file.

3. When the flush () or ob_flush () function is called.

In the actual production environment, we can speed up your site by flushing the PHP buffer immediately after the head tag. The sample code is as follows:

Buffer flushing in action...

Next, let's explain what the above code does:

When the browser receives the code for the head section of the page, it can start downloading the resources included in the head section, such as CSS files, site favorite icons (Favicon), and so on. The download of this content can be synchronized with the time when the browser accepts the content of the body segment.

How much can be accelerated, it needs to be adjusted to local conditions. This depends on many objective conditions, including the server's response speed, your page size, the size and number of your CSS files, whether the browser has a local cache, and so on. There are many factors, but such a small optimization can obviously speed up your site, so why not?

This is the end of the content of "what circumstances will cause PHP buffer flushing". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report