Home Backend Development PHP Tutorial ob_start()求教解决思路

ob_start()求教解决思路

Jun 13, 2016 pm 01:20 PM
content echo start

ob_start()求教
ob_start(); //-----------------------------1

//for($s=0;$s
//ob_end_clean(); //----------------------------------2

for($var=0;$var echo $var;
print str_repeat("", 4096); 
ob_flush();//--------------------------3
flush(); //--------------------------4
  sleep(1); //--------------------------5
}
?>
一个测试缓冲区的例子,问题来了,当使用ob_start()函数时候,【3】的作用是释放缓冲区的内容,【4】将不再缓冲区的内容发送到页面,【5】使得每秒发送一次,但是为什么还会等10秒后一次将内容全发送过去.

查了很多文章,很多都说使用【2】处的方法,注释掉【1】【3】,但是这样就关闭了缓冲区,

网上关于Php的说法有称内部缓冲区的,也有叫缓冲区的,不知道是不是一个东西。
还有Php.ini文件中的 output_buffering他的缓冲区是不是就是ob_start()开启的缓冲区?

------解决方案--------------------
ob_flush不是很好用,请参考官方文档。
http://il.php.net/manual/en/function.ob-flush.php

some problems with ob_flush() and flush() could be resolved by defining content type header :
header( 'Content-type: text/html; charset=utf-8' );

so working code looks like this:
header( 'Content-type: text/html; charset=utf-8' );
echo 'Begin ...
';
for( $i = 0 ; $i {
echo $i . '
';
flush();
ob_flush();
sleep(1);
}
echo 'End ...
';
?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if docker start cannot start? What should I do if docker start cannot start? Oct 21, 2022 pm 03:43 PM

What should I do if docker start cannot start?

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

Implementing distributed task scheduling using Golang's web framework Echo framework

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP

Explore the Go language framework: 5 choices not to be missed! Explore the Go language framework: 5 choices not to be missed! Feb 19, 2024 pm 02:29 PM

Explore the Go language framework: 5 choices not to be missed!

Let's explore, what are the commonly used frameworks in Go language? Let's explore, what are the commonly used frameworks in Go language? Feb 18, 2024 pm 10:53 PM

Let's explore, what are the commonly used frameworks in Go language?

See all articles