Wordpress cronjob every 5 seconds not working












1















I've added following into my Wordpress functions.php file to send a mail every 5 seconds to the entered email address but it's not working. I've added some logging to check if the job runs the hook but it's just initializing it and thats it:



add_filter( 'cron_schedules', 'five_seconds_interval' );
function five_seconds_interval( $schedules ) {
$schedules['five_seconds'] = array(
'interval' => 5,
'display' => esc_html__( 'Alle 5 Sekunden' ),
);

return $schedules;
}

add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_job');
}

function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}


This is what I'm getting in my logfile:



[14-Nov-2018 17:31:24 UTC] schedule_my_cron()


I've also disabled the normal cronjob for Wordpress in my config file:




define( 'DISABLE_WP_CRON', true );




After this I've created a unix cronjob which works fine. So I'm expecting that when I run the unix cronjob every 5 seconds that I'm getting my mail sent to the address. Whats wrong?



Update



I can confirm that my custom schedule was added successfully, here is part of the output from wp get schedules():



[five_seconds] => Array
(
[interval] => 5
[display] => Alle 5 Sekunden
)









share|improve this question

























  • After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

    – miken32
    Nov 14 '18 at 17:50






  • 1





    Yes, added successfully sir. Look at my question.

    – Mr. Jo
    Nov 14 '18 at 17:54
















1















I've added following into my Wordpress functions.php file to send a mail every 5 seconds to the entered email address but it's not working. I've added some logging to check if the job runs the hook but it's just initializing it and thats it:



add_filter( 'cron_schedules', 'five_seconds_interval' );
function five_seconds_interval( $schedules ) {
$schedules['five_seconds'] = array(
'interval' => 5,
'display' => esc_html__( 'Alle 5 Sekunden' ),
);

return $schedules;
}

add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_job');
}

function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}


This is what I'm getting in my logfile:



[14-Nov-2018 17:31:24 UTC] schedule_my_cron()


I've also disabled the normal cronjob for Wordpress in my config file:




define( 'DISABLE_WP_CRON', true );




After this I've created a unix cronjob which works fine. So I'm expecting that when I run the unix cronjob every 5 seconds that I'm getting my mail sent to the address. Whats wrong?



Update



I can confirm that my custom schedule was added successfully, here is part of the output from wp get schedules():



[five_seconds] => Array
(
[interval] => 5
[display] => Alle 5 Sekunden
)









share|improve this question

























  • After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

    – miken32
    Nov 14 '18 at 17:50






  • 1





    Yes, added successfully sir. Look at my question.

    – Mr. Jo
    Nov 14 '18 at 17:54














1












1








1








I've added following into my Wordpress functions.php file to send a mail every 5 seconds to the entered email address but it's not working. I've added some logging to check if the job runs the hook but it's just initializing it and thats it:



add_filter( 'cron_schedules', 'five_seconds_interval' );
function five_seconds_interval( $schedules ) {
$schedules['five_seconds'] = array(
'interval' => 5,
'display' => esc_html__( 'Alle 5 Sekunden' ),
);

return $schedules;
}

add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_job');
}

function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}


This is what I'm getting in my logfile:



[14-Nov-2018 17:31:24 UTC] schedule_my_cron()


I've also disabled the normal cronjob for Wordpress in my config file:




define( 'DISABLE_WP_CRON', true );




After this I've created a unix cronjob which works fine. So I'm expecting that when I run the unix cronjob every 5 seconds that I'm getting my mail sent to the address. Whats wrong?



Update



I can confirm that my custom schedule was added successfully, here is part of the output from wp get schedules():



[five_seconds] => Array
(
[interval] => 5
[display] => Alle 5 Sekunden
)









share|improve this question
















I've added following into my Wordpress functions.php file to send a mail every 5 seconds to the entered email address but it's not working. I've added some logging to check if the job runs the hook but it's just initializing it and thats it:



add_filter( 'cron_schedules', 'five_seconds_interval' );
function five_seconds_interval( $schedules ) {
$schedules['five_seconds'] = array(
'interval' => 5,
'display' => esc_html__( 'Alle 5 Sekunden' ),
);

return $schedules;
}

add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_job');
}

function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}


This is what I'm getting in my logfile:



[14-Nov-2018 17:31:24 UTC] schedule_my_cron()


I've also disabled the normal cronjob for Wordpress in my config file:




define( 'DISABLE_WP_CRON', true );




After this I've created a unix cronjob which works fine. So I'm expecting that when I run the unix cronjob every 5 seconds that I'm getting my mail sent to the address. Whats wrong?



Update



I can confirm that my custom schedule was added successfully, here is part of the output from wp get schedules():



[five_seconds] => Array
(
[interval] => 5
[display] => Alle 5 Sekunden
)






php wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:00









miken32

23.9k84972




23.9k84972










asked Nov 14 '18 at 17:37









Mr. JoMr. Jo

731116




731116













  • After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

    – miken32
    Nov 14 '18 at 17:50






  • 1





    Yes, added successfully sir. Look at my question.

    – Mr. Jo
    Nov 14 '18 at 17:54



















  • After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

    – miken32
    Nov 14 '18 at 17:50






  • 1





    Yes, added successfully sir. Look at my question.

    – Mr. Jo
    Nov 14 '18 at 17:54

















After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

– miken32
Nov 14 '18 at 17:50





After creating your custom schedule, have you confirmed it was added successfully? It should be in the return from wp get schedules().

– miken32
Nov 14 '18 at 17:50




1




1





Yes, added successfully sir. Look at my question.

– Mr. Jo
Nov 14 '18 at 17:54





Yes, added successfully sir. Look at my question.

– Mr. Jo
Nov 14 '18 at 17:54












1 Answer
1






active

oldest

votes


















3














According to the documentation for the function you need to use add_action() for the function being called on schedule, not the function doing the scheduling. The third parameter to wp_schedule_event() is the name of an action hook, not a function name. Try something like this:



register_activation_hook(__FILE__, 'schedule_my_cron');
add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_five_second_event');
}

add_action('my_five_second_event', 'my_job');
function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}





share|improve this answer


























  • Now it's working. Thanks a lot for your help sir! Have a great day.

    – Mr. Jo
    Nov 14 '18 at 18:07













  • Can you upvote my question if you like it? :)

    – Mr. Jo
    Nov 14 '18 at 18:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305889%2fwordpress-cronjob-every-5-seconds-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














According to the documentation for the function you need to use add_action() for the function being called on schedule, not the function doing the scheduling. The third parameter to wp_schedule_event() is the name of an action hook, not a function name. Try something like this:



register_activation_hook(__FILE__, 'schedule_my_cron');
add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_five_second_event');
}

add_action('my_five_second_event', 'my_job');
function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}





share|improve this answer


























  • Now it's working. Thanks a lot for your help sir! Have a great day.

    – Mr. Jo
    Nov 14 '18 at 18:07













  • Can you upvote my question if you like it? :)

    – Mr. Jo
    Nov 14 '18 at 18:09
















3














According to the documentation for the function you need to use add_action() for the function being called on schedule, not the function doing the scheduling. The third parameter to wp_schedule_event() is the name of an action hook, not a function name. Try something like this:



register_activation_hook(__FILE__, 'schedule_my_cron');
add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_five_second_event');
}

add_action('my_five_second_event', 'my_job');
function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}





share|improve this answer


























  • Now it's working. Thanks a lot for your help sir! Have a great day.

    – Mr. Jo
    Nov 14 '18 at 18:07













  • Can you upvote my question if you like it? :)

    – Mr. Jo
    Nov 14 '18 at 18:09














3












3








3







According to the documentation for the function you need to use add_action() for the function being called on schedule, not the function doing the scheduling. The third parameter to wp_schedule_event() is the name of an action hook, not a function name. Try something like this:



register_activation_hook(__FILE__, 'schedule_my_cron');
add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_five_second_event');
}

add_action('my_five_second_event', 'my_job');
function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}





share|improve this answer















According to the documentation for the function you need to use add_action() for the function being called on schedule, not the function doing the scheduling. The third parameter to wp_schedule_event() is the name of an action hook, not a function name. Try something like this:



register_activation_hook(__FILE__, 'schedule_my_cron');
add_action('init', 'schedule_my_cron',10);
function schedule_my_cron(){
error_log("schedule_my_cron()");
wp_schedule_event(time(), 'five_seconds', 'my_five_second_event');
}

add_action('my_five_second_event', 'my_job');
function my_job() {
error_log("my_job()");
wp_mail('test@localhost.de', 'Cronjob funktioniert!', 'LOL', 'Von IBims');
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 18:05









Mr. Jo

731116




731116










answered Nov 14 '18 at 17:41









miken32miken32

23.9k84972




23.9k84972













  • Now it's working. Thanks a lot for your help sir! Have a great day.

    – Mr. Jo
    Nov 14 '18 at 18:07













  • Can you upvote my question if you like it? :)

    – Mr. Jo
    Nov 14 '18 at 18:09



















  • Now it's working. Thanks a lot for your help sir! Have a great day.

    – Mr. Jo
    Nov 14 '18 at 18:07













  • Can you upvote my question if you like it? :)

    – Mr. Jo
    Nov 14 '18 at 18:09

















Now it's working. Thanks a lot for your help sir! Have a great day.

– Mr. Jo
Nov 14 '18 at 18:07







Now it's working. Thanks a lot for your help sir! Have a great day.

– Mr. Jo
Nov 14 '18 at 18:07















Can you upvote my question if you like it? :)

– Mr. Jo
Nov 14 '18 at 18:09





Can you upvote my question if you like it? :)

– Mr. Jo
Nov 14 '18 at 18:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305889%2fwordpress-cronjob-every-5-seconds-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python