Scheduled Tasks
Learning Essentials:
How to set a common command for a scheduled task
How to run PHP programs regularly
Most of the PHP programs run on Linux, where the Linux
Commands for timed tasks:
1. Scheduled Task Service provides crontab command to set up the service;
2.cronrab-e//Edit a user's cron service;
3.crontab-l//list details of a user's cron service;
4.crontab-r//Delete a user's cron service;
Open Terminal software
Enter the command:
crontab-eEnter password
Go to a blank page
Input
*/1 * * * */usr/bin/php/usr/local/apaehc2/htdocs/test.php
Usecrontab-lView
UseCrontab-rDelete
Format of timed task crontab
Sub-hourly date month-week order
* * * * *
0-59 0-24 1-31 1-12 0-6 command
Attention:
"*" represents a number in the range of values
"/" stands for each, such as every minute, etc.
*/1 * * * * * per minute execution
50 7 * * * 7:50 execution per day
Timed tasks combined with PHP case
How do I insert data into a data table every minute?
1. Inserting data into the data table;
2. Scheduled Tasks
Vim cron.php
<?php
$connect = mysql_connect (' 127.0.0.1 ', ' root ', ' pass ');
mysql_select_db (' dbname ');
$sql = "INSERT into dbname values ()";
mysql_query ($sql);
?>
After inserting, we'll see the data.
Input command
crontab-e
*/1 * * * */usr/bin/php/usr/local/apache2/htdocs/cron.php
This will execute every minute.
PHP Development App Interface (VI)