PHP timed execution program code

Source: Internet
Author: User

 

Scheduled code execution <? Php ignore_user_abort (); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled. set_time_limit (0); // the execution time is unlimited. The default php Execution time is 30 seconds. You can use set_time_limit (0) to allow unlimited execution of the program $ interval = 20; // time interval in seconds $ key_file = "key.txt"; // configuration file if (isset ($ _ GET ['s ']) {if ($ _ GET ['s '] = "0") {// stop the job, but do not exit $ s = "false "; echo "Function is off";} elseif ($ _ GET ['s '] = "1") {// working $ s = "true "; echo "Function is on";} elseif ($ _ GET ['s '] = "2") {// exit $ s = "die "; Echo" Function exited ";} else die (" Err 0: stop working 1: working 2: exit "); $ string =" <? Php \ n return \ "". $ s. "\"; \ n?> "; Write_inc ($ key_file, $ string, true); exit () ;}if (file_exists ($ key_file) {do {$ mkey = include $ key_file; if ($ mkey = "true ") {// if the job is // work interval //////////// /// // $ showtime = date ("Y-m-d H: i: s "); $ fp = fopen('func.txt ', 'A'); fwrite ($ fp, $ showtime. "\ n"); fclose ($ fp ); //////////////////////////////////////// /// //} elseif ($ mkey = "die ") {// exit di E ("I am dying! ");} Sleep ($ interval); // wait $ interval minutes} while (true);} else die ($ key_file." doesn't exist! "); Function write_inc ($ path, $ strings, $ type = false) {$ path = dirname (_ FILE __). "/". $ path; if ($ type = false) file_put_contents ($ path, $ strings, FILE_APPEND); else file_put_contents ($ path, $ strings) ;}?>

Original article: http://blbear.com/post/187

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.