Php, wait 5 seconds before executing an action

前端 未结 7 621
执笔经年
执笔经年 2021-02-05 00:42

I have a .php script that I use for creating the list of my products. I am on shared hosting, so I can\'t do a lot of queries otherwise I get a blank page.

This

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 01:21

    i use this

        $i = 1;
        $last_time = $_SERVER['REQUEST_TIME'];
        while($i > 0){
            $total = $_SERVER['REQUEST_TIME'] - $last_time;
            if($total >= 2){
                // Code Here
                $i = -1;
            }
        }
    

    you can use

    function WaitForSec($sec){
        $i = 1;
        $last_time = $_SERVER['REQUEST_TIME'];
        while($i > 0){
            $total = $_SERVER['REQUEST_TIME'] - $last_time;
            if($total >= 2){
                return 1;
                $i = -1;
            }
        }
    }
    

    and run code =>

    WaitForSec(your_sec);
    

    Example :

    WaitForSec(5);
    

    OR you can use sleep

    Example :

    sleep(5);
    

提交回复
热议问题