際際滷

際際滷Share a Scribd company logo
WordPress Cron
仍舒亟亳仄亳 弌从仍, WordCamp Russia 2014
Wordpress Cron
仗亠舒亳仂仆仆亠 亳亠仄
 Windows
仍舒仆亳仂于亳从 亰舒亟舒 (丐ask scheduler)
 Linux
cron  仗仂于仂ム亳亠 亰舒亟舒亳
at  仂亟亳仆仂仆亠 亰舒亟舒亳
仍舒仆亳仂于亳从亳 亰舒亟舒 弌
仍舒仆亳仂于亳从 仂仆亳亞舒亳
Wordpress Cron
舒亟舒亳 于 磲亠 WordPress
 仂于亠从舒 仂弍仆仂于仍亠仆亳亶
 仗仍舒亞亳仆仂于
 亠仄
 磲舒
 丕亟舒仍亠仆亳亠 亰舒仗亳亠亶 亳亰
从仂亰亳仆
 丕亟舒仍亠仆亳亠 舒于仂仂舒仆亠仆亳亶
亟亳仆仂仆亠 仂于仂ム亳亠
 弍仍亳从舒亳
亰舒仗仍舒仆亳仂于舒仆仆 亰舒仗亳亠亶
 仗舒于从舒 仗亳仆亞仂于
Wordpress Cron
弍舒从仆舒 亠仄舒 仗仍舒仆亳仂于亳从舒 WordPress
仍舒仆亳仂于亳从

/wp-cron.php
仂仆亳亞舒亳

Cron API
wp_options cron
舒仗从
仗仍舒仆亳仂于亳从舒
舒弍仂舒 仗仍舒仆亳仂于亳从舒 WordPress 于 亟亠舒仍
init
wp_cron()
spawn_cron()
...
/wp-cron.php
...
http
仂亰仄仂亢仆亠 仗仂弍仍亠仄
 亳亰从舒 仗仂亠舒亠仄仂
 亰舒仗从  仗仂仄仂 仗仍舒仆亳仂于亳从舒 弌
 仂从舒 仗仂亠舒亠仄仂
 仗仍舒仆亳仂于亳从 舒舒亠 仄舒从亳仄舒仍仆仂 亳从仍ム亳 于仂亰仄仂亢仆仂
于仗仂仍仆亠仆亳 仂亟仆仂亶 亰舒亟舒亳 仆亠从仂仍从亳仄亳 仗仂亠舒仄亳 仂亟仆仂于亠仄亠仆仆仂
WP_CRON_LOCK_TIMEOUT = 60 亠从仆亟
http://wordpress.org/plugins/wp-missed-schedule/
仍舒亞亳仆 束WP Missed 皆界鞄艶糸顎鉛艶損
舒仗从 亠亠亰 Linux Cron
// wp-config.php
define('DISABLE_WP_CRON', true);
# crontab -e
*/15 * * * * wget -q -O  "http://example.com/wp-cron.php" > /dev/null 2>&1
crontab-generator.org
corntab.com
仍亠仆舒亳于仆亶 亠亢亳仄 亰舒仗从舒
init
wp_cron()
spawn_cron()
include ''wp-cron.php'';
...
http://example.com/?wp_doing_cron
仍亠仆舒亳于仆亶 亠亢亳仄 亰舒仗从舒
// wp-config.php
define( 'ALTERNATE_WP_CRON' , true );
舒仗从  仗仂仄仂 仂仂仆仆亳 亠于亳仂于
 EasyCron - https://www.easycron.com/
 仗仍舒亞亳仆 - http://wordpress.org/plugins/easycron/
 SetCronJob - https://www.setcronjob.com/
 ...
Cron API
/wp-includes/cron.php
action
callback
callback
callback
callback
亟亳仆仂仆亠 亰舒亟舒亳
wp_schedule_single_event(
time() + 3600, // 于亠仄 亰舒仗从舒
"hook_name", // 亳仄 仂弍亳
array( $arg1, $arg2, $arg3 ) // 舒亞仄亠仆
);
add_action( "hook_name", "hook_callback" , 10, 3 );
function hook_callback ( $arg1, $arg2, $arg3 ) {
// 从仂亟 亰舒亟舒亳
}
仂于仂ム亳亠 亰舒亟舒亳
wp_schedule_event(
time() + 60, // 于亠仄 仗亠于仂亞仂 亰舒仗从舒
"hourly", // 亳仄 亳仆亠于舒仍舒
"hook_name", // 亳仄 仂弍亳
array( $arg1, $arg2, $arg3 ) // 舒亞仄亠仆
);
add_action( "hook_name", "hook_callback", 10, 3 );
function hook_callback ( $arg1, $arg2, $arg3 ) {
// 从仂亟 亰舒亟舒亳
}
舒亟舒舒
仆亠于舒仍
于仗仂仍仆亠仆亳
仆亠于舒仍 仗仂于仂磳仄 亰舒亟舒
["hourly"] => [
["interval"] => 3600,
["display"] => "舒亢亟亶 舒",
],
["daily"] => [
["interval"] => 86400,
["display"] => "舒亢亟亶 亟亠仆",
],
["twicedaily"] => [
["interval"] => 43200,
["display"] => "于舒 舒亰舒 于 亟亠仆",
]
弌仂亰亟舒仆亳亠 仗仂仍亰仂于舒亠仍从亳 亳仆亠于舒仍仂于
add_filter( "cron_schedules" , "add_custom_cron_interval" );
function add_custom_cron_interval ( $intervals ) {
$intervals["weekly"] = array(
"interval" => WEEK_IN_SECONDS,
"display" => "舒亢亟 仆亠亟亠仍",
);
return $intervals;
}
仂于仂ム亳亠 亰舒亟舒亳
wp_schedule_event(
time() + 60, // 于亠仄 仗亠于仂亞仂 亰舒仗从舒
"hourly", // 亳仄 亳仆亠于舒仍舒
"hook_name", // 亳仄 仂弍亳
array( $arg1, $arg2, $arg3 ) // 舒亞仄亠仆
);
add_action( "hook_name", "hook_callback", 10, 3 );
function hook_callback ( $arg1, $arg2, $arg3 ) {
// 从仂亟 亰舒亟舒亳
}
丕亟舒仍亠仆亳亠 亰舒亟舒
wp_unschedule_event()
wp_clear_scheduled_hook()
仍舒亞亳仆
WP Crontrol
http://wordpress.org/plugins/wp-crontrol/
Wordpress Cron
仍舒亞亳仆
Debug Bar Cron - http://wordpress.org/plugins/debug-bar-cron/
WP-CLI - http://wp-cli.org/
Multisite
束WordPress Cron損
仍舒亟亳仄亳 弌从仍 (versus.post@gmail.com), WordCamp Russia 2014

More Related Content

Wordpress Cron