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.