php ob

ob是output buffering的简称,就是输出缓冲区,并不是output cache,用对了对速度有帮助,盲目用会增加CPU负担。
如果使用了ob_start函数,那么之后的输出内容(echo等)就不进行实际输出,而是存入缓冲区里面,随后可以使用ob_flush实际输出、ob_clean删除、ob_get_contents获得内容保存到静态文件等。
使用输出缓冲区有两个主要的好处:一是可以在输出一些内容之后在设置header(例如cookie等),使得程序设计的逻辑性变得简单;二是可以对缓冲区里面的输出内容撤销、删除、压缩、保存到文件等操作。
ob_clean — Clean (erase) the output buffer
ob_end_clean — Clean (erase) the output buffer and turn off output buffering
ob_end_flush — Flush (send) the output buffer and turn off output buffering
ob_flush — Flush (send) the output buffer
ob_get_clean — Get current buffer contents and delete current output buffer
ob_get_contents — Return the contents of the output buffer
ob_get_flush — Flush the output buffer, return it as a string and turn off output buffering
ob_get_length — Return the length of the output buffer
ob_get_level — Return the nesting level of the output buffering mechanism
ob_get_status — Get status of output buffers
ob_gzhandler — ob_start callback function to gzip output buffer
ob_implicit_flush — Turn implicit flush on/off
ob_list_handlers — List all output handlers in use
ob_start — Turn on output buffering
output_add_rewrite_var — Add URL rewriter values
output_reset_rewrite_vars — Reset URL rewriter values
典型应用:将phpinfo()的信息写到文件里.
ob_start(); 
phpinfo(); 
$phpinfo = ob_get_contents(); 
//文件读写操作
ob_clean(); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值