admin管理员组

文章数量:1302904

I have a staging server begind basic auth and I'd like to run system cron instead of WordPress 'cron'.

I've placed the define('DISABLE_WP_CRON', true); in my wp-config.php, and first I've added

*/5 * * * * curl -u user:pass .php?doing_wp_cron

but then I thought to myself, why don't I just ping the file directly?

*/5 * * * * php /home/mysite_staging/www/example/wp-cron.php?doing_wp_cron

Is there a difference in doing this, besides not using curl to execute a request? Is executing a request a necessary step?

I have a staging server begind basic auth and I'd like to run system cron instead of WordPress 'cron'.

I've placed the define('DISABLE_WP_CRON', true); in my wp-config.php, and first I've added

*/5 * * * * curl -u user:pass https://example/wp-cron.php?doing_wp_cron

but then I thought to myself, why don't I just ping the file directly?

*/5 * * * * php /home/mysite_staging/www/example/wp-cron.php?doing_wp_cron

Is there a difference in doing this, besides not using curl to execute a request? Is executing a request a necessary step?

Share Improve this question asked Mar 17, 2021 at 13:55 dingo_ddingo_d 1,9602 gold badges25 silver badges48 bronze badges 4
  • Ping what file? If you have a file in a theme or plugin that you want to hit directly then that file cannot use any WordPress functions or APIs. – Jacob Peattie Commented Mar 17, 2021 at 14:05
  • wp-cron.php file. So a curl request towards the wp-cron.php?doing_wp_cron will also bootstrap the entire WP, but php wp-cron.php?doing_wp_cron won't and that's the problem (if my hunch is right)? I just need to trigger cron events. – dingo_d Commented Mar 17, 2021 at 14:21
  • php won't work because you need to send a POST request. Even if you didn't, loading the file would still bootstrap WordPress. It needs to to work properly. Otherwise what would you be running? The scheduled events are added by WordPress, themes, and plugins, so they obviously all need to be loaded. – Jacob Peattie Commented Mar 17, 2021 at 14:37
  • Yeah, I just realized it depends on the GET parameter

    本文标签: Manually running cron from the server