我創建了一個使用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