I want to schedule a cron job from my plugin using wp_cron
but came to know that it only checks for cron only on page load. Is there any way to run a cron job even if the page is not loaded? Since I want to run this cron from my plugin on customer's server, I can't even run system cron instead of wp_cron
? Any alternative to solve this problem? How does plugin like task scheduler do that?
1 Answer
Cron jobs are simply PHP scripts that are controlled by time. If the PHP file is not executed, the cron job will not be executed either.
Your option would be to set a cron job in your host's control panel, to ping a page once in a while. You can ask your host's support to do this for you, since it's different on each control panel and OS, and a bit complicated.
-
As I already mentioned, I want to schedule cron from my plugin which I will ship to WordPress users. I can't control other's host– beginnerFeb 9, 2018 at 5:07
-
2Then this is the only option. Someone has to execute your script. If it’s not the system cron job, then it’s a visitor to your wensite, triggering wp-cron in the background. Feb 9, 2018 at 7:54