2014-10-10 41 views
0

我有一個shell腳本,它在php文件中執行以獲取溫度。如何在PHP中循環運行ShellScript

<?php 
    $output = shell_exec('sh temperature.sh'); 
    echo "<pre>$output&deg;C</pre>"; 
?> 

現在它只修改一次。 我該如何更改php文件,使Value始終保持最新?

謝謝

+2

http://www.w3schools.com/php/php_looping.asp先看看while/for循環。它會給你改變你的PHP代碼好主意 – 2014-10-10 16:18:10

+0

@ArunSangal php循環與他的問題無關 – Dima 2014-10-10 17:08:13

回答

1

PHP是服務器端語言。這意味着當它的加載完成後。 如果你想永遠更新它,你應該使用ajax調用。

var interval = 1000; // 1 second 
function doAjax() { 
    $.ajax({ 
     type: 'GET', 
     url: 'get_what_you_want.php', 
     data: {}, 
     dataType: 'json', 
     success: function (data) { 
       $('body').text(data) // or put it on your page  
     }, 
     complete: function (data) { 
       // Schedule the next 
       setTimeout(doAjax, interval); 
     } 
    }); 
} 
setTimeout(doAjax, interval);