Join NairaMan / Login / Trending / Recent / New
Stats: 2,325 members, 5,885 topics. Date: October 21, 2018, 2:56 am
What is a cron job?
A cron job is a task scheduled to run at a particular time interval or time of day. Cron jobs are used on all Unix-like operating system for administrative background tasks run once per day, week or month. If you need to run a particular job every day, hour or 5 minutes on a standard Linux server, you would use a cron job to do that.
Traditionally, cron jobs are set up on the terminal (see the Wikipedia article on Cron for geeky details) but these days you can usually create a cron job right in your hosting control panel. If you're using cPanel, you can find some tutorials on cron jobs in cPanel here or here - or simply google for "setting up cron jobs in cPanel".
How WordPress does it: WP-Cron
Usually, the average WordPress site runs very well without setting up a cron job at all. But there are a few features in WordPress core which rely on scheduled background tasks - like scheduling a post to be published at a specific date and time. How does WordPress manage to do this without an actual cron job?
Whenever someone visits your site WordPress checks if there any background tasks scheduled to run. If there are, WordPress will internally request the URL http://www.example.com/wp-cron.php, which triggers the task schedule to be executed via wp_cron. This request is sent asynchronously (WordPress doesn't wait for it to finish) to make sure it has no impact on your site performance.
Why use an external cron job?
The main limitation of using WP-Cron is the fact that you need to have traffic on your site in order to run scheduled background tasks. It doesn't matter if it's you, a customer or a search engine spider visiting your site. But if there is no traffic at all, no scheduled background tasks will be executed - which affects all tasks scheduled by WordPress plugins as well.
Imagine there is no traffic during the night on your site, but you get a new sale on eBay. WP-Lister for eBay will not "know" about this new sale until its scheduled tasks are executed - so the stock in WooCommerce will not be reduced right away. This is not an actual problem if you only sell on eBay and your own website: The moment a customer visits your website, the stock will be reduced automatically - before anyone could purchase it in WooCommerce.
However, if you're selling on Amazon as well, there is a problem as your stock level on Amazon would not be reduced until there is some traffic on your site again.
To prevent overselling in such a case, it is highly recommended that you use an external cron job to make sure that both WP-Lister for eBay and WP-Lister for Amazon check for new orders every 5 to 15 minutes.
There have also been cases where a rouge plugin or wrong server configuration causes WordPress wp_cron scheduler to fail. Since any plugin can register tasks with wp_cron, any plugin can break it as well. If that is happening on your site, the safest workaround is using an external cron job which doesn't rely on wp_cron at all.
How to use an external cron job?
To use an external cron job with WP-Lister, you first have to enable it in WP-Lister and then follow the instructions to create the actual cron job either on your server or using a web based cron job service.
Repeat these steps for both WP-Lister for Amazon and WP-Lister for eBay:
Visit the general settings page
Set the update interval option to use external cron job
Click Save Settings
Click on Details in the right sidebar
You will see the following information appear in a new window - using your actual site URL instead of example.com:
You can ask your server admin to set up a cron job on your own server - or use a 3rd party web based cron service, which provides a user friendly interface and additional features for a small annual fee.
Option A: Web cron service
The easiest way to set up a cron job is to sign up with www.easycron.com and use the following URL to create a new task:
Option B: Server cron job
If you prefer to set up a cron job on your own server you can create a cron job that will execute the following command:
wget -q -O - http://example.com/wp-admin/admin-ajax.php?action=wplister_run_scheduled_tasks >/dev/null 2>&1
Once you have created your cron job either way, check the general settings page after a while where you will see when the scheduled tasks ran last. With a cron job set to run every 15 minutes, you should never see anything more than "15 min. ago".
For the record: We are not affiliated with EasyCron in any way. They are just a user friendly alternative for less geeky users or users without access to cron jobs on their webspace.
Web Based Cron Job Services
https://www.easycron.com/ (free plan requires monthly renewal)
https://www.setcronjob.com/ (starting at $10/year)
https://www.externalcronjobs.com/ ($19/year, REST API, Slack notifications)
https://cronless.com/ (starting at $27/year, free plan not suitable)
https://cronitor.io/ (free for 1 cron job)
How to prevent your system from WannaCry Ransomware / Java Programming Course For Beginners And Advance.... / Hundred percent sure fixed games on bet9ja and all other betting platform / Acada Suite – School Management Application You Don’t Want to Miss / How to set up an external cron job / Make money selling webhosting /
Viewing this topic: 1 guest viewing this topic
|NairaMan - Copyright © 2012 - 2018 John Onam. All rights reserved. See NairaMan and NairaBlog|
Disclaimer: Every NairaMan member is solely responsible for anything that he/she posts or uploads on NairaMan.