我创建了一个使用PHP的后台进程,但我打算用while(1)
来测试它,无限地执行它。给出结果,但重复的结果,如:PHP无限循环结果没有重复,但更新
Result 1 text: Hi! Result 2 text: Hello! Result 1 text: Hi! Result 2 text: Hello!
我不知道做的是,它不会重复,但是当有新的变化,如价值也将被更新:
初始运行:
Result 1 text: Hi! Result 2 text: Hello!
当有变化:
Result 1 text: Hello! Result 2 text: Hello!
上面的场景是只是例子,但脚本连接到数据库。
更新:我的代码。
<?php
@ini_set("output_buffering", "Off");
@ini_set('implicit_flush', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('max_execution_time',1200);
require("database.php");
while(1){
$sqlReports = "SELECT * FROM reports WHERE reports.process = 'F'";
$resReports = odbc_exec($conn,$sqlReports);
while($reports = odbc_fetch_array($resReports))
{
echo $reports['reportnum']. "</br>";
$sqlStations = "SELECT * FROM stations";
$resStations = odbc_exec($conn,$sqlStations);
while($stations = odbc_fetch_array($resStations))
{
echo $stations['name']. "</br>";
}
sleep(1);
flush();
ob_flush();
}
}
?>
结果代码:
1 station1 station2 station3 2 station1 station2 station3 3 station1 station2 station3 1 station1 station2 station3 2 station1 station2 station3 ...
我想的是,它不会再次显示显示的号码,但它会更新,如果有喜欢的变化:在循环过程
没有更新:
1 station1 station2 station3 2 station1 station2 station3 3 station1 station2 station3
在循环过程更新时间:
1 station1 station2 station5 2 station6 station2 station3 3 station7 station8 station9
你能证明你所尝试过的吗?一些代码? –
请包括您到目前为止尝试过的代码 – Cyval
从哪里得到这些数据? D b?你为什么使用while循环而不是cronjob? – Rizier123