Delayed execution program-php Tutorial

Source: Internet
Author: User
There is a program for delayed execution. I want to execute a program every minute. what is the PHP idea? how can I write it?
For example, for (I = 0; I <1000; I ++ ){
Program Logic
I want to delay one minute before executing the task and then perform the next loop. how can I write this? it seems that the php page has been timed out for a long time?
}


Reply to discussion (solution)

For ($ I = 0; I I <1000; $ I ++ ){
Echo $ I;
Sleep (60); // runs every 60 seconds
}

Use sleep ();

We recommend that you use system scheduled tasks.

Will SLEEP be canceled due to system timeout?

Will SLEEP be canceled due to system timeout?

Will SLEEP be canceled due to system timeout?
Set_time_limit (0) does not time out and quit.

The page is always open,
Set_time_limit (0); does not time out the page
Sleep (60); this allows the program to sleep for 60 seconds before execution.

But it is not recommended to do this. it mainly depends on your logic. We recommend that you use crontab.
Enter

Crontab-e ***** php handle. php> handle. log: wq

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.