PHP timer function

0

Does anyone know of a timer function like the setTimeOut of javascript: link

Only in PHP?

Because I'm trying to do with Sleep, but the page loads infinitely.

function Criar_Madeira($a) {
        $a->madeira += 500;
        sleep(10);
        Criar_Madeira($a);
}

Criar_Madeira($a[1]);
    
asked by anonymous 14.05.2018 / 05:24

2 answers

0

PHP is server-side , so this can only be done on the client side, in this case, javascript.

    
14.05.2018 / 05:32
0

You called the function inside the function, and when you do that, it's going to be looping endlessly, you know? Because she will run the same all over again, and will end up running the part she is called again.

function criarMadeira($a) { //Por que precisa desse parâmetro?
    sleep(10);  
    $this->madeira += 500;
}

criarMadeira(1); //Não entendi o porque desse valor 1

Remember that PHP also works cascading, things run from top to bottom. With sleep before, it will execute $this->madeira += 500; only after it.

    
14.05.2018 / 13:47