Wordpress cronjob every 5 seconds not working
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
add a comment |
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
After creating your custom schedule, have you confirmed it was added successfully? It should be in the return fromwp 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
add a comment |
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
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
php wordpress
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 fromwp 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
add a comment |
After creating your custom schedule, have you confirmed it was added successfully? It should be in the return fromwp 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
add a comment |
1 Answer
1
active
oldest
votes
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');
}
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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');
}
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
add a comment |
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');
}
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
add a comment |
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');
}
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');
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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