PHP sleep function background process

时间:2016-07-11 21:32:54

标签: javascript php process background sleep

How can i execute PHP sleep() function as a background process with AJAX or other Javascript? Or can you tell me alternatives of this function?

1 个答案:

答案 0 :(得分:0)

You can use the Javascript setInterval function to periodically call your random dice function every given interval (in the example below I set this to 3 seconds. This will be much more efficient than using sleep.

<script>
var myVar = setInterval(function(){ randomDice() }, 3000); // 3000 ms = 3s

function randomDice() {
    //assign random number and write to some div
}
</script>