PHP实现即时输出、实时输出内容方法
这篇文章主要介绍了PHP实现即时输出、实时输出内容方法,本文直接给出实现方法,需要的朋友可以参考下
老生长谈了。。纯备忘
对于运行时间较长的PHP程序来说可能都需要即时输出内容来查看运行情况。
代码如下:
header(“Content-type:text/html;charset=utf-8″);
#设置执行时间不限时
set_time_limit(0);
#清除并关闭缓冲,输出到浏览器之前使用这个函数。
ob_end_clean();
#控制隐式缓冲泻出,默认off,打开时,对每个 print/echo 或者输出命令的结果都发送到浏览器。
ob_implicit_flush(1);
例,
代码如下:
ob_end_clean();
ob_implicit_flush(1);
while(1){
//部分浏览器需要内容达到一定长度了才输出
echo str_repeat("
", 200).'hello sjolzy.cn
';
sleep(1);
//ob_end_flush();
//ob_flush();
//flush();
}
按例子测试,达到了PHP即时实时输出内容的效果。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version