Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MerryChristmas's avatar

How to run PHP script every 5 seconds?

How to run vanilla PHP script every 5 seconds? (only one instance of this script can be run at the time) So ideally run script 5 seconds from the time script stopped last time.

I have my own Ubuntu server.

0 likes
8 replies
Lara_Love's avatar
function update() {
    $.ajax({
        url: 'update.php', //php          
        data: "", //the data "caller=name1&&callee=name2"
        dataType: 'json', //data format   
        success: function (data) {
            //on receive of reply
            var foobar = data[2]; //foobar
            $('#verification').html("(<b>" + foobar + "</b>)"); //output to html
        }
    });
}

$(document).ready(update); // Call on page load



setInterval(update, 5000); //every5 secs
Snapey's avatar

setup a php script that calls the other one every 5 seconds then use supervisor to make sure it keeps running

MerryChristmas's avatar

@Snapey how do you mean to call other script? Like file_get_content or making 'command line like' execution command? Won't the first script wait for execution of second script?

Please or to participate in this conversation.