PHP implementation of scheduled task execution

Source: Internet
Author: User
Tags sleep function
This article mainly introduces PHP's method for implementing scheduled task execution, which involves the use of the ignore_user_abort function to ignore the termination of the script and the delayed execution of the sleep function, for more information about how to implement scheduled task execution in PHP, see the following example. the code is simple and practical. Share it with you for your reference.

The specific implementation method is as follows:

Ignore_user_abort (true); // when the client is disconnected, ignore the script abort (allow the script to be executed all the time) set_time_limit (0); // set the maximum script execution time, 0 do {$ handle = fopen('auto.txt ', 'w'); if ($ fp) {$ text = 'Hello \ n \ r'; $ count = 0; for ($ I = 1; $ I <10; $ I ++) {if (! $ C = fwrite ($ handle, 'dide '. $ I. 'row :'. $ text) // returns the number of written characters. if a failure occurs, false {echo 'quarter 'is returned '. $ I. 'write failed! ';}$ Count + = $ c ;}} fclose ($ handle); sleep (60); // wait 60 seconds for execution} while (true );

I hope this article will help you with PHP programming.

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.