WordPress.org

Ready to get started?Download WordPress

Forums

cron job does not work, why? (5 posts)

  1. flarefox
    Member
    Posted 3 years ago #

    The interval of "debug60s" is 60 seconds.

    if (!wp_next_scheduled('auto_update_sddl_event')) {
    // only for debug
    	$file = fopen("c:/1.txt", "a");
    	fwrite($file, "0");
    	fclose($file);
    	wp_schedule_event(current_time('timestamp'), 'debug60s', 'auto_update_sddl_event');
    }
    
    function auto_update_sddl_func() {
    // only for debug
    	$file = fopen("c:/1.txt", "a");
    	fwrite($file, "1");
    	fclose($file);
    }
    add_action('auto_update_sddl_event', 'auto_update_sddl_func');

    I wish auto_update_sddl_func would execute every 60 seconds. However, it's never run, not even once. In the file "C:/1.txt" I can only find "0".

    I've read codex but still have no idea at all. Can you help me? Thanks a looot!

  2. flarefox
    Member
    Posted 3 years ago #

    The steps to run a cron job are:
    1. use add_action to assign a function to a hook.
    2. use wp_schedule_event to add the hook into cron list.
    3. wait until the scheduled time has passed, then refresh wp site one times, the function will execute.

    Can you tell me whether these steps are correct? pls. Thanks!

  3. flarefox
    Member
    Posted 3 years ago #

    Anyone can help? pls...

  4. Joey Kudish
    Member
    Posted 3 years ago #

    What is debug60s, where are you defining this?

    Take a look at the documentation here: http://codex.wordpress.org/Function_Reference/wp_schedule_event

  5. flarefox
    Member
    Posted 3 years ago #

    This question has been solved. The reason is time zone.

    wp_schedule_event(current_time('timestamp'), 'debug60s', 'auto_update_sddl_event');
    After I changed it to be
    wp_schedule_event(time(), 'debug60s', 'auto_update_sddl_event');

    It worked fine.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.