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