Go online Check, first is the Sleep series (sleep/usleep/nanosleep/time_sleep_until) function, first of these functions have a problem, sleep is the current process hangs, such as:
echo time();sleep(10);echo time();
In fact, " wait for 10 seconds ", " again " Display two timestamp, the time difference between timestamps 10 seconds.
And the effect I want is to show the first timestamp first, wait 10 seconds, and then show the second timestamp.
So:
I want to break out of the current dead loop by using an infinite loop and then judging the difference between the current time and the stored time. Like what:
for(100遍){//一些操作$start = time();while(true){if(time() - $start == 1)break;}}
Meaning the For loop executes every time, at the end it goes into a dead loop, and then jumps out of the loop for 1 seconds, continuing the next for loop.
But, however, incredibly is the cycle of death!!!
Then tried it:
while(true){echo time();}
Incredibly unchanged!!! and echo out date (' s ') is changed!!!
So I want to ask:
1, if the need to meet the delay in the implementation of the demand, do not sleep, do not thread, simply is suspended under the execution (in fact, I do the crawler, high frequency will be 302), in addition to the above dead cycle of the way there are other ways? (Not AJAX, PHP only)
2. Why is the time () unchanged?
Reply content:
Go online Check, first is the Sleep series (sleep/usleep/nanosleep/time_sleep_until) function, first of these functions have a problem, sleep is the current process hangs, such as:
echo time();sleep(10);echo time();
In fact, " wait for 10 seconds ", " again " Display two timestamp, the time difference between timestamps 10 seconds.
And the effect I want is to show the first timestamp first, wait 10 seconds, and then show the second timestamp.
So:
I want to break out of the current dead loop by using an infinite loop and then judging the difference between the current time and the stored time. Like what:
for(100遍){//一些操作$start = time();while(true){if(time() - $start == 1)break;}}
Meaning the For loop executes every time, at the end it goes into a dead loop, and then jumps out of the loop for 1 seconds, continuing the next for loop.
But, however, incredibly is the cycle of death!!!
Then tried it:
while(true){echo time();}
Incredibly unchanged!!! and echo out date (' s ') is changed!!!
So I want to ask:
1, if the need to meet the delay in the implementation of the demand, do not sleep, do not thread, simply is suspended under the execution (in fact, I do the crawler, high frequency will be 302), in addition to the above dead cycle of the way there are other ways? (Not AJAX, PHP only)
2. Why is the time () unchanged?
Sleep does allow the program to pause, after all, you get two timestamp difference 10 seconds, but why is 10s after the show it together? Because the content of the first output is still in buffer, turn off the output cache to see the effect you wantob_end_flush();
Such a cycle, 1 seconds can output hundreds of thousands of millions of times, the same second of course, the same, 1s will certainly change.