• 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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter flarefox

    (@flarefox)

    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!

    Thread Starter flarefox

    (@flarefox)

    Anyone can help? pls…

    What is debug60s, where are you defining this?

    Take a look at the documentation here: https://codex.www.ads-software.com/Function_Reference/wp_schedule_event

    Thread Starter flarefox

    (@flarefox)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘cron job does not work, why?’ is closed to new replies.