PHP Buffer ob

Source: Internet
Author: User

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 is not really output, but saved in the buffer    Echo"Hello"; Echo"Word"; //getting data from a buffer    $info=ob_get_contents(); //close and clear buffers    Ob_end_clean(); Var_dump($info);//output: String ' Helloword ' (length=9)

PHP Buffer ob

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.