You can use the ignore_user_abort function to schedule tasks in PHP. For more information, see.
You can use the ignore_user_abort function to schedule tasks in PHP. For more information, see.
Forget this function:
Function Name: ignore_user_abort
Whether or not the PHP program continues to be executed on the Hong Kong server after the function is configured or the connection is interrupted on the user side. The default value is to stop running after the connection is interrupted. In the PHP configuration file (php3.ini/php. ini), The ignore_user_abort option is the configuration. This function is available only after PHP 3.0.7.
Official notes:
Usage:
The Code is as follows:
Ignore_user_abort (true); // The PHP script can be executed even if the Client is disconnected (such as the browser is disabled.
In this way, you can achieve the task scheduling effect, but you still need to access the program from the client.
For example, when generating static pages and collecting data, there is no record-filing space, and Hong Kong servers are rented, so there is no need to wait. Turn off the browser.
Example:
The Code is as follows:
// Test
Set_time_limit (0 );
Ignore_user_abort (true );
$ I = 0;
While ($ I ++ <200 ){
File_put_contents ($ I. '. php', $ I );
Sleep (3 );
}
Use the ignore_user_abort function to implement php Task Scheduling
The Code is as follows:
Ignore_user_abort (true );
Set_time_limit (0 );
While (1 ){
$ Fp = fopen('time_task.txt ', "a + ");
$ Str = date ("Y-m-d h: I: s"). "\ n \ r ";
Fwrite ($ fp, $ str );
Fclose ($ fp );
Sleep (5); // run once every 30 minutes
}
?>