【发布时间】:2013-05-29 03:37:13
【问题描述】:
我正在使用 php,我在 php 中看到 while() 循环。我想问一下我们可以使用while() 循环作为mysql_unbuffered_query()。
这段代码很好理解。
<?php
echo 'While Loop is going to start';
$i = 0;
while($i <= 1000){
echo 'Now number is '.$i;
$i++;
}
echo 'Continue to running script';
?>
当我们首先运行这段代码时会发生什么,这段代码读取while loop is going to start
然后阅读 while 循环并创建要运行的语句Now number is 0.....1000
然后阅读Continue to running script 当代码完成它打印出整个数据。但我不想要这个。
我想要什么。
第一个脚本读取 while Loop is going to start 并打印出来,然后读取 while 循环和
打印出Now number is 0 然后转到Continue to running script 并打印出但是
后端脚本while循环仍在工作,我的意思是while loop和continue script同时工作。
这让你更了解。
OUTPUT(脚本运行的第一次开始)
1 - While Loop is going to start
2 - Now number is 0
3 - Continue to running script
输出(脚本运行继续)
1 - While Loop is going to start
2 - Now number is 0
3 - Now number is 1
. - ...............
1000 - Now number is 1000
1001 - Continue to running script
这可能是不可能。如果是,我该怎么做。
但也许这可能像mysql_unbuffered_query()。
就像当 while 循环完成一个循环时,它会打印出数字,然后打印出另一个,依此类推。
输出(第一次当 while 循环完成一个循环时)
1 - While Loop is going to start
2 - Now number is 0
输出(while循环完成第二个循环)
1 - While Loop is going to start
2 - Now number is 0
3 - Now number is 1
如果可能,请指导我如何做到这一点。
谢谢............
【问题讨论】:
-
你做的一切都是对的......只需在 echo 语句后添加
flush(); -
首先不推荐使用mysql。请使用 mysqli 或 PDO。二、为什么不用ob_flush?
-
我正在使用
flush();,但这不起作用。<?php ini_set('implicit_flush', true); echo 'While Loop is going to start'; $i = 0; while($i <= 1000){ echo 'Now number is '.$i; flush(); $i++; } echo 'Continue to running script'; ?> -
你是想说你想在后台线程中运行你的循环吗?
标签: php while-loop