2010-04-19 21 views
1

我想監視我在Web服務器上運行的程序。 我可以繪製進度條,還是隻顯示我的代碼返回的百分比? php腳本產生具有參數的外部代碼。顯示計算進度的方法是什麼?

$Status="rendering..."; 
$cmd = "cd $rpath && $envopts /home/arm2arm/bin/sph2grid"; 
$shellcmd=$cmd.$params.'| tee sph2grid.log '; 
echo '<strong>'.$shellcmd.'</strong>'; 
$tmp=shell_exec($shellcmd); 

那麼畢竟我顯示日誌文件:

<?php 
function ViewLog() { 
$string = file_get_contents('../../PHP-Login/tmp/sph2grid.log'); 
$string = str_replace("\n", '<br>', $string); 
echo $string; 
}  
?> 

我可以綁定我的應用程序的輸出一些"<div>"

在此先感謝。

Arman。

回答

3

U可以使用JavaScript來設置定時器間隔,該間隔產生ajax進程來輪詢輸出百分比的php頁面。然後你可以抓住該網頁的響應,並將其附加到一個div:

setInterval (pollPage, 1000); 
function pollPage() 
{ 
    $.get("percentageComplete.php",output); 
} 

function output(data) 
{ 
    $("#yourDiv").empty().append(data); 

} 

在percentageComplete.php你需要得到完成計算

+0

的百分比不幸的是這裏最難的部分是你放什麼percentComplete.php文件 – 2010-04-19 13:11:54

+0

好,這取決於正在記錄什麼。 PHP文件可以解析日誌並獲取該信息。 – Luis 2010-04-19 13:29:47

+0

感謝您的解決方案。有沒有辦法停止計時器?我應該把計時器放到無窮遠處來阻止它嗎? – Arman 2010-04-19 21:11:25

相關問題