Reputation: 53
In wordpress, I have worked to create a cron job.Currently, The Cron job displays the logs only when somebody visits the page. But, i want it to run without any page visit. I know that can be done. But how , that is what i dont know. Please guide me friends. I have used the function wp_scheduled_event
Upvotes: 1
Views: 340
Reputation: 4156
This is normal behaviour. Wordpress crons are not server crons, they depend of PHP to be executed, so it'll run only if someone visit your website.
From wp_schedule_event
documentation:
The action will trigger when someone visits your WordPress site, if the scheduled time has passed.
You'll need a server cron if you want to get through this limitation. Depends of your hosting, you may be able to configure a cron through the manager, or if you have SSH access on your server (so if it's not a shared hosting), execute this command :
crontab -e
It'll open your crontab file. Add this line inside to add a cron job:
*/30 * * * * php-cli -f /path/to/your/php/script.php
Replace with the correct path to your php script. This command will execute the script every 30 minutes - change this to whatever you need (read more).
If you're on a shared hosting and your manager doesn't allow you to create cron jobs, you could maybe use an online service like this one to execute your script.
Upvotes: 2