最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Wordpress Console Application (ability to excecute a custom function via crontab only)

programmeradmin0浏览0评论

I have a few custom tables in the database and I need to clean expired data from time to time.

If I was using WP-Cron, it would be easy, but WP-Cron sucks and is a no-go (especially for what I am doing). Having that in mind, I need to launch some code using crontab. How should I do it in a clean, effective manner that would not require nasty hacks?

I was thinking of creating a REST endpoint, but how to protect it so it could only be opened by the crontab?

The solution should be inside the plugin folder so it could be stored in GIT easily (i.e. nasty workarounds storing files in the main folder (a.k.a public_html) are not welcomed).

Was searching for a good solution for hours with no success... Thanks in advance!

I have a few custom tables in the database and I need to clean expired data from time to time.

If I was using WP-Cron, it would be easy, but WP-Cron sucks and is a no-go (especially for what I am doing). Having that in mind, I need to launch some code using crontab. How should I do it in a clean, effective manner that would not require nasty hacks?

I was thinking of creating a REST endpoint, but how to protect it so it could only be opened by the crontab?

The solution should be inside the plugin folder so it could be stored in GIT easily (i.e. nasty workarounds storing files in the main folder (a.k.a public_html) are not welcomed).

Was searching for a good solution for hours with no success... Thanks in advance!

Share Improve this question asked Aug 13, 2020 at 10:48 Mindaugas JakubauskasMindaugas Jakubauskas 1646 bronze badges 2
  • 2 Have you tried launching WP Cron via crontab instead? WP Cron normally relies on a nonblocking request when a user visits because WP can't modify crontab, but if you have access to crontab you can trigger it at regular intervals so it always runs even if nobody visits, and at specific intervals. On my own site I trigger it every 5 minutes via a cron job, and I recently changed it to use a job manager such as Cavalcade to run cron events. Even WP CLI can trigger it – Tom J Nowell Commented Aug 13, 2020 at 11:53
  • @TomJNowell genius! Haha, sometimes the answer is so obvious that it's hard to see :D Thanks a lot!! – Mindaugas Jakubauskas Commented Aug 14, 2020 at 12:03
Add a comment  | 

1 Answer 1

Reset to default 1

The solution is as @Tom J Nowell mentioned to launch WP Cron via crontab (and disable it on user visits).

发布评论

评论列表(0)

  1. 暂无评论