Home > Backend Development > PHP Tutorial > PHP real-time output

PHP real-time output

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-28 08:25:40
Original
925 people have browsed it

Generally, PHP will output the content to be output to the page only after all tasks have been executed. For example, the following code:

<span>for</span> (<span>$i</span> = 0;<span>$i</span><10;<span>$i</span>++<span>) {
    </span><span>echo</span><span>$i</span><span>;
    </span><span>sleep</span>(1<span>);
}</span>
Copy after login

This code will output "0123456789" in one go after 10 seconds ".

But sometimes we need to output the content immediately after executing the output function during the execution of the PHP page without waiting for the page to be fully executed. We modify the code to the following:

 PHP實時輸出

<span>set_time_limit</span>(0<span>);
</span><span>echo</span><span>str_pad</span>('',1024);<span>//</span><span>使用另一個字符串填充字符串為指定長度;</span><span>ob_implicit_flush</span>(<span>true</span>);<span>//</span><span>打開/關閉絕對發送;</span><span>for</span>(<span>$i</span>=1;<span>$i</span><10;<span>$i</span>++<span>){
    </span><span>echo</span><span>$i</span><span>;
    </span><span>sleep</span>(1<span>);
}</span>
Copy after login

 PHP實時輸出

In this way, the page will output a number every second.

We can easily use PHP’s output control to display the page execution progress. However, since PHP pages have execution time limits, and executing a page for a long time will put a certain amount of pressure on the server. So I use it appropriately.

The above has introduced PHP real-time output, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template