This article mainly introduces the introduction of PHP cache area ob, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Introduction:
ob is the abbreviation of output buffering, output buffer, and the buffer is controlled through the output_buffering variable in php.ini. Its default value is off and can be set to on to open the buffer. After calling the buffer, even if the ob function is not used in the program, the code actually uses the buffer. In addition, regardless of the setting of output_buffering in php.ini, php in cli mode is always turned off by default. Why a buffer? To put it simply, the high-speed CPU has processed its own data early and wants to transmit it to the user through the line, but the line is too narrow and cannot be transmitted at once. If a buffer is introduced, the CPU can quickly put the generated data into the buffer, and then rest somewhere cool. The buffer outputs data in a timely manner according to instructions. This effectively solves the contradiction between high-speed CPU and low-speed I/O devices.
Basic principles of use:
If the ob cache is turned on, the echo data is first placed in the ob cache. If it is header information, it is placed directly in the program cache. When the page is executed to the end, the ob cached data will be placed in the program cache, and then returned to the browser in turn.
Basic usage:
// 开启OB ob_start(); //输出一些内容,此时输出的内容并不会真正输出,而是保存在缓冲区 echo "hello"; echo "word"; //从缓冲区获取数据 $info = ob_get_contents(); //关闭并清空缓冲区 ob_end_clean(); var_dump($info); //输出:string 'helloword' (length=9)
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Unlimited classification and infinite nested comments in PHP
thinkphp multi-image ajax upload image
The above is the detailed content of Introduction to PHP cache area ob. For more information, please follow other related articles on the PHP Chinese website!