Web is something that will always have the complete answer, if you use sleep
you will have problems, headaches, especially if you have session_start
, understand that I am not saying that sleep is bad, the use of the way proposed in the other answers is not ideal.
I think it's best to use Ajax and popular a DIV, for example:
foo / temperatura.php
<?php
function retornaTemperatura()
{
// Local do arquivo python
$comando = escapeshellcmd('temperatura.py');
// retorna o valor do py para exibir ou mandar para um banco de dados
return shell_exec($comando);
}
echo retornaTemperatura();
And on your page call something like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="temperatura"></div>
<script type="text/javascript">
function temperatura()
{
var el = document.getElementById("temperatura");
var segundos = 2; //2 segundos de espera
var oReq = new XMLHttpRequest();
//Defina como true
oReq.open("GET", "/foo/temperatura.php", true);
//Função assíncrona que aguarda a resposta
oReq.onreadystatechange = function()
{
if (oReq.readyState == 4) {
if (oReq.status == 200) {
el.innerHTML = oReq.responseText;
}
setTimeout(temperatura, segundos * 1000);
}
};
//Envia a requisição, mas a resposta fica sendo aguardada em Background
oReq.send(null);
}
</script>
</body>
</html>