How To Use setInterval in PHP?

后端 未结 8 1906
刺人心
刺人心 2020-12-08 16:11

I want to ask that how can i use php function again and again after some time automatically just like setInterval in Javascript. We set the time and it is on its job until t

相关标签:
8条回答
  • 2020-12-08 17:12

    Unlike Javascript, PHP is executed on the server side. There is no setTimeout functionality in PHP. You can get close by using cronjobs - or other PHP scripts - that call your scripts though.

    0 讨论(0)
  • 2020-12-08 17:14

    I would suggest using setInterval to poll for results from a .php page using AJAx and then output your results.

    So it would look something like this using jQuery:

    <script>
        var poll = true;
        var getData = function() {
            if (poll) {
                $.get('getData.php', function(data) { $('#likes').html(data); });
            }
        };
    
        $(document).ready(function() {
            setInterval(getData, 5000);
            $('.comm').click(function() { poll = false; });
            $('.comm').blur(function() { poll = true; });
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题