This article mainly introduces the introduction of the PHP buffer ob, has a certain reference value, now share to everyone, the need for friends can refer to
Introduced:
The OB is the abbreviation for output buffering, and the buffer is controlled by the output_buffering variable in the php.ini. The default value is off, which can be set to on to open buffer. After hitting buffer, even if the program does not use the OB function, the code is actually using the buffer. In addition, PHP is always turned off by default in CLI mode, regardless of the output_buffering settings in php.ini. Why, what if the buffer zone? In short, the high-speed CPU processing their own data early, want to pass the line to the user, but the line is too narrow, the delivery is not over. If a buffer is introduced, the CPU can quickly put the generated data into a buffer, and then where it is cool where to stay and rest. Buffers output data in a timely manner according to the instructions. This kind of a reasonable solution to the high-speed CPU and low-speed I/O equipment contradictions.
Basic principles of Use:
If the OB cache is open, the echo data is first placed in the OB cache. If it is header information, put it directly in the program cache. When the page executes to the end, the data of the OB cache is placed in the program cache and returned to the browser in turn.
Basic methods of Use:
Open ob Ob_start (); Output some content, at this time the output of the content will not be really output, but save in the buffer echo "Hello"; echo "word"; Get data from buffer $info = ob_get_contents (); Close and clear the buffer Ob_end_clean (); Var_dump ($info); Output: String ' Helloword ' (length=9)
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!