As a cron job does not run until a page load request comes, what will happen in case page-loaded is being served from cache by some caching plugin? Will WordPress still run a cron job that is scheduled to run in this case?
-
Depends on the cache, you should ask the plugin author. But if it's not loading WordPress, then probably not. You can set up a cron job on the server to hit wp-cron.php periodically though.– Jacob PeattieCommented Feb 9, 2018 at 0:33
-
Actually, I have to run a cron job from my plugin, so can't change plugin user's server config.– learning_13Commented Feb 9, 2018 at 0:43
-
Then isn't this their problem?– Jacob PeattieCommented Feb 9, 2018 at 0:46
-
But as a plugin developer, I want to keep my data updated on a scheduled basis and can't be dependent on my plugin users cron configuration– learning_13Commented Feb 10, 2018 at 18:42
1 Answer
It depends on the plugin and the cache method you are using. For example, as far as I remember, WP Super Cache offers two different cache methods:
PHP Cache
HTML Cache
Using the first method creates PHP cache files that still load WordPress's functions, but do not go through the whole loading process. If this is the case, it means that the PHP functions are executed, and your cron job will probably be processed. However, since the cron jobs are usually in the theme's functions.php
file, and the PHP cache file is usually a PHP template cache, there is a chance that it won't trigger. You should have a closer look at the generated PHP cache files.
The second method simply creates status HTML files that are served directly. There is no PHP involved in this, so no cron job will be executed.