I checked it online. First, the sleep series (sleepusleepnanosleeptime_sleep_until) functions. First, these functions have a problem. sleep is suspended by the current process, for example: {code ...} in fact, after [wait for 10 seconds], [and at the same time] Two timestamps are displayed, timestamps... I checked it online. The first is the sleep series (sleep/usleep/nanosleep/time_sleep_until) functions. First, these functions have a problem. sleep is suspended by the current process, for example:
echo time();sleep(10);echo time();
Actually 【Wait 10 secondsAfter ,【At the same timeTwo timestamps are displayed, with a difference of 10 seconds.
The effect I want is to first display the first timestamp, wait 10 seconds, and then display the second timestamp.
So:
I want to use an infinite loop and then determine the difference between the current time and the pre-stored time to break the current endless loop. For example:
For (100 times) {// some operations $ start = time (); while (true) {if (time ()-$ start = 1) break ;}}
It means that every time a for loop is executed, it enters an endless loop at the end, and then jumps out of the endless loop every second to continue the next for loop.
However, it is an endless loop !!!
Then I tried:
while(true){echo time();}
Not changed !!! The date ('s') generated by echo is changed !!!
So I want to ask:
1. If we need to meet the demand for delayed execution, we should not sleep or thread, simply pause and execute again (in fact, I am a crawler and the frequency will be 302 if it is too high ), is there any other way besides the above endless loop? (Do not use AJAX, only on the PHP side)
2. Why does that time () remain unchanged?
Reply content:
I checked it online. The first is the sleep series (sleep/usleep/nanosleep/time_sleep_until) functions. First, these functions have a problem. sleep is suspended by the current process, for example:
echo time();sleep(10);echo time();
Actually 【Wait 10 secondsAfter ,【At the same timeTwo timestamps are displayed, with a difference of 10 seconds.
The effect I want is to first display the first timestamp, wait 10 seconds, and then display the second timestamp.
So:
I want to use an infinite loop and then determine the difference between the current time and the pre-stored time to break the current endless loop. For example:
For (100 times) {// some operations $ start = time (); while (true) {if (time ()-$ start = 1) break ;}}
It means that every time a for loop is executed, it enters an endless loop at the end, and then jumps out of the endless loop every second to continue the next for loop.
However, it is an endless loop !!!
Then I tried:
while(true){echo time();}
Not changed !!! The date ('s') generated by echo is changed !!!
So I want to ask:
1. If we need to meet the demand for delayed execution, we should not sleep or thread, simply pause and execute again (in fact, I am a crawler and the frequency will be 302 if it is too high ), is there any other way besides the above endless loop? (Do not use AJAX, only on the PHP side)
2. Why does that time () remain unchanged?
Sleep does pause the program. After all, the two timestamps you get differ by 10 seconds, but why are they displayed after 10 seconds? Because the content output for the first time is still in the buffer, close the output cache to see what you want.ob_end_flush();
In such a loop, hundreds of thousands of times can be output within one second. Of course, they are all the same in the same second. It will certainly change after one second.