Disable wp-cron
Still, we need to disable WordPress default wp-cron behaviour by adding following line to wp-config.php file:
This will stop the internal WP-Cron function from executing on every page load.
Please note:You are not disabling the WP Cron itself. You just disabling it’s execution by WordPress on every pageload and replacing it with execution by regular cronjob. cronjob will execute all WP Cron tasks.
Set Up a Linux Cron
To create or edit a crontab file run the following command:
Note: without –delete-after option, wget would save the output of the HTTP GET request.
A daily call to your site’s WordPress Cron that triggers at midnight every night could look similar to:
2分钟一次
cURL (Preferable)未测试
OR
wget
如何判断定时任务正常执行?
1.首先确认crontab有正常调用你的命令
查看下cron的日志: tail /var/log/cron,看到类似如下的日志说明crontab有在正常调用命令。
显示情况
List Existing Cron Jobs
You can list all cron jobs on your system without opening the crontab configuration file. Type in the following command in a terminal window:
Basic Crontab Syntax
Cron reads the configuration files for a list of commands to execute. The daemon uses a specific syntax to interpret the lines in the crontab configuration tables.
To be able to set up a cron job, we need to understand the basic elements that make up this syntax. The standard form for a crontab line is as follows:
a b c d e /directory/command output
So, the parts of a cron command are:
1. The first five fields a b c d e specify the time/date and recurrence of the job.
2. In the second section, the /directory/command specifies the location and script you want to run.
3. The final segment output is optional. It defines how the system notifies the user of the job completion.
1. Cron Job Time Format
The first five fields in the command represent numbers that define when and how often the command runs. A space separates each position, which represents a specific value.
The table below summarizes possible values for the fields and the example syntax:
Field | Possible Values | Syntax | Description |
[a] – Minute | 0 – 59 | 7 * * * * | The cron job is initiated every time the system clock shows 7 in the minute’s position. |
[b] – Hour | 0 – 23 | 0 7 * * * | The cron job runs any time the system clock shows 7am (7pm would be coded as 19). |
[c] – Day | 0 – 31 | 0 0 7 * * | The day of the month is 7 which means that the job runs every 7th day of the month. |
[d] – Month | 0 = none and 12 = December | 0 0 0 7 * | The numerical month is 7 which determines that the job runs only in July. |
[e] – Day of the Week | 0 = Sunday and 7 = Sunday | 0 0 * * 7 | 7 in the current position means that the job would only run on Sundays. |
评论
必须登陆才能发表评论.