0

I have a shell script which is excecuted in a php file to get the temperature.

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

Right now it is only excecuted once. How do I need to change the php file so the Value is always up to date?

Thanks

2
  • 2
    w3schools.com/php/php_looping.asp see while/for loop here first. It'll give you good idea on changing your PHP code Commented Oct 10, 2014 at 16:18
  • @ArunSangal php loop has nothing to do with his question Commented Oct 10, 2014 at 17:08

1 Answer 1

1

PHP is a server side language. that means that when its loaded, its done. if you want to update it always, you should use ajax calls for that.

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.