際際滷

際際滷Share a Scribd company logo
Cron API
于 WordPress
仍舒亟亳仄亳 弌从仍, WordPress Meetup Moscow #25, 26.04.2014
亳仄亠 亰舒仗仍舒仆亳仂于舒仆仆 亰舒亟舒 于
亠舒仍仆仂亳:
仂于仂ム亳亠
 舒亢亟亶 亟亠仆 仂仄 亳亳仄 亰弍
 舒亢亟亶 弍亟仆亳亶 亟亠仆 亳亟仄 仆舒 舒弍仂 于 8:00
 亠仆 仂亢亟亠仆亳 亳 亟亞亳亠 仗舒亰亟仆亳从亳
 舒亢亟亶 仄亠 仗仍舒亳仄 亰舒 从于舒亳
亟亳仆仂仆亠
 仂仆亠 仗仂仗仍仆仂亞仂 舒亳舒
 仂仍亠仆亳亠 仗舒仗仂舒 于 18 仍亠
 舒仄亠仆舒 仍仂仗仆于亠亞仂 从仂仍亠舒 舒于仂仄仂弍亳仍 =)
亳仄亠 亰舒仗仍舒仆亳仂于舒仆仆 亰舒亟舒 于
仗仂亞舒仄仄舒:
 仂于亠从舒 仂弍仆仂于仍亠仆亳亶
 亳从舒 仍仂亞仂于
 仗舒于从舒 仂仂于 仗仂 仗仂亠
 弍仆仂于仍亠仆亳亠 从亠舒 (仆舒仗亳仄亠: 亟仍 于仆亠仆亳 亰舒仗仂仂于)
舒仗仍舒仆亳仂于舒仆仆亠 亰舒亟舒亳 于 WordPress:
亟亳仆仂仆亠
 弍仍亳亳 亰舒仗仍舒仆亳仂于舒仆仆 亰舒仗亳亠亶
 仗舒于从舒 仗亳仆亞仂于
仂于仂ム亳亠
 仂于亠从舒 仂弍仆仂于仍亠仆亳亶
 仍舒亞亳仆仂于
 丐亠仄
 亊亟舒
 丕亟舒仍亠仆亳亠 亰舒仗亳亠亶 亳亰 从仂亰亳仆
 丕亟舒仍亠仆亳亠 舒于仂仂舒仆亠仆亳亶
舒从 仂 舒弍仂舒亠
/wp-cron.php
仂弍仍亠仄
WordPress Cron API
亠亠仆亳亠 (从仂仍)
仍舒亞亳仆 - WP Missed Schedule
http://wordpress.org/plugins/wp-missed-schedule/
WordPress Cron API
舒仗从 wp-cron.php 亳亰于仆亠
//wp-config.php
define('DISABLE_WP_CRON', true);
// crontab -e
*/15 * * * * wget -q -O  "http://example.com/wp-cron.php" > /dev/null 2>&1
0 */1 * * * wget -q -O  "http://example.com/wp-cron.php" > /dev/null 2>&1
0 3 * * * wget -q -O  "http://example.com/wp-cron.php" > /dev/null 2>&1
从仍ム亠仆亳亠 亟亞仂亞仂 亠亢亳仄舒 舒弍仂
//wp-config.php
define('ALTERNATE_WP_CRON', true);
亟亳仆仂仆亠 亰舒亟舒仆亳
wp_schedule_single_event( time() + 3600, event_name, array( $arg1, $arg2, $arg3 ) );
function do_this_in_an_hour( $arg1, $arg2, $arg3 ) {
// 从仂亟 从仂仂亶 于仗仂仍仆亳 仗亳 亰舒仗从亠 亰舒仗仍舒仆亳仂于舒仆仆仂亶 亰舒亟舒亳
}
add_action( event_name, do_this_in_an_hour, 10, 3 );
仂于仂ム亳亠 亰舒亟舒仆亳
wp_schedule_event( time(), hourly, hook_name );
add_action( hook_name, my_function );
function my_function () {
// 从仂亟 从仂仂亶 于仗仂仍仆亳 仗亳 亰舒仗从亠 亰舒仗仍舒仆亳仂于舒仆仆仂亶 亰舒亟舒亳
}
仆亠于舒仍 于仗仂仍仆亠仆亳
Array
(
[twicedaily] => Array
(
[interval] => 43200
[display] => 于舒 舒亰舒 于 亟亠仆
)
[hourly] => Array
(
[interval] => 3600
[display] => 舒亢亟亶 舒
)
[daily] => Array
(
[interval] => 86400
[display] => 舒亢亟亶 亟亠仆
)
)
add_filter( cron_schedules , add_custom_cron_intervals );
function add_custom_cron_intervals ( $intervals ) {
$intervals[weekly] = array(
interval => WEEK_IN_SECONDS,
display => __( Once Weekly , my-textdomain ),
);
$intervals[half_hour] = array(
interval => MINUTE_IN_SECONDS * 30,
display => __( Every 30 minutes , my-textdomain ),
);
return $intervals;
}
丕亟舒仍亠仆亳亠 仂弍亳亶
$timestamp = wp_next_scheduled( 'my_schedule_hook' );
$original_args = array();
wp_unschedule_event( $timestamp, 'my_schedule_hook', $original_args );
wp_clear_scheduled_hook( 'my_new_event' );
个亳仍
cron_schedules
cron_request
schedule_event
/wp-cron.php  从亳仗 于仗仂仍仆ム亳亶 亰舒仗仍舒仆亳仂于舒仆仆亠 亰舒亟舒亳
/wp-includes/cron.php  仆亠仗仂亠亟于亠仆仆仂 Cron API
仂仆舒仆
DISABLE_WP_CRON
ALTERNATE_WP_CRON
WP_CRON_LOCK_TIMEOUT
DOING_CRON
丐舒仆亰亳仆亶 从亠
doing_cron
wp_options  cron - 舒弍仍亳舒 于  亳 仆舒亰于舒仆亳亠 仂仗亳亳 仂亟亠亢舒亠亶 仗亳仂从 亰舒亟舒
WordPress Cron API
wp_get_schedules_get_cron_array
_set_cron_array
_upgrade_cron_array
_get_cron_lock
wp_reschedule_event
wp_cron
spawn_cron
WordPress Cron API
wp_schedule_event
wp_schedule_single_event
wp_unschedule_event
wp_clear_scheduled_hook
wp_next_scheduled
wp_get_schedule
弌仂亰亟舒仆亳亠 亰舒亟舒
仆仂仄舒亳 仂
亰舒亟舒舒
丕亟舒仍亠仆亳亠
弌仍亢亠弍仆亠 舒仗从 于仗仂仍仆亠仆亳 仆亠于舒仍
弌从舒 仗亳从舒 亰舒仗仍舒仆亳仂于舒仆仆 亰舒亟舒, 舒仆亳仄仂亞仂 于 
Array
(
[1398537004] => Array
(
[wp_scheduled_delete] => Array
(
[40cd750bba9870f18aada2478b24840a] => Array
(
[schedule] => daily
[args] => Array ()
[interval] => 86400
)
)
)
[1408985132] => Array
(
[publish_future_post] => Array
(
[ac7fd96c96bfd48cea1794b86e78b348] => Array
(
[schedule] =>
[args] => Array
(
[0] => 140
)
)
)
)
)
仍舒亞亳仆
WP Crontrol - http://wordpress.org/plugins/wp-crontrol/
Debug Bar Cron - http://wordpress.org/plugins/debug-bar-cron/
WordPress Cron API
仂仍亠亰仆亠 仍从亳
smashingmagazine.com - Schedule Events Using WordPress Cron - http://bit.ly/1ehMFev
themefm.com - WordPress Internals: The Cron - http://bit.ly/1kdx1me
仂仗仂

More Related Content

WordPress Cron API