如何在PHP中循环运行ShellScript


HowTo run a ShellScript in PHP in loop

我有一个shell脚本,它在php文件中被优化以获取温度。

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

现在它只被超越了一次。我需要如何更改php文件,使Value始终是最新的?

感谢

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);