Product Update Cronjob¶
Table of contents
Use this cronjob to automatically update the items in your Products section (see Products).
This way you can avoid products being updated via API when a visitor opens a page.
To learn more about cronjobs in general, check out the Introduction chapter.
To learn more about setting up and using ASA2’s cronjobs, see the dedicated Cronjob Setup chapter.
The internal name of this cornjob is
Therefore, use it with the Server-side execution like this:
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --cat=31,40 --lifetime=7200
$cronWrapper = new \Asa2\Cron\Wrapper('Asa2_Module_Repo_Cron_Refresh'); $cronWrapper->setOptions([ 'limit' => 10, 'cat' => '31,40', 'lifetime' => 7200 ]); $cronWrapper->execute();
The REST API endpoint name of this cronjob is
Check Cron REST API for more details about running ASA2’s cronjobs via URL.
It is highly recommended to use this cronjob in combination with option Server-side request limit handling.
If you are a power user with several hundret products to be refreshed via this cronjob, you should use the server-side cronjob.
Let’s assume you have 250 products in your Products section and you want to refresh them once a day. If you configure the cronjob to run once every hour, it should refresh 11 products in every run: 250 products / 24 hours = 10.41 products per hour.
To make sure all 250 products will be handled within 24 hours, set option
lifetime to “86400” (seconds) which means a product will only get refreshed once per day.
Replace [wp_path] with the local server path of your WordPress installation.
This cron job will run at minute zero, every hour:
0 * * * * /[wp_path]/wp-content/plugins/amazon-simple-affiliate/scripts/script.sh Asa2_Module_Repo_Cron_Refresh --lifetime=86400 --limit=11
There are several Options you can use to fit the cronjob to your requirements.
bash script.sh Asa2_Module_Repo_Cron_Refresh -lt=3600 --limit=50 -cat=31 tag=sale --verbose --log --logpath=/home/me/tmp/asa2
To find your perfect settings, please check ASA2’s cronjob calculator.
cat option to filter the results by category ID. You can define multiple categories as comma separated list.
For example, only update repo items from category 31 and 40.
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40
Filters the result of prodcuts to be updated by country code. Mulitple country codes must be separated by comma.
// update 10 items from the US and German store: bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --country_code=DE,US // update all items from the Canadian store bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=-1 --country_code=CA
By using this option, only products that have an ASIN (i.e. Amazon products) will be updated.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --having_asin=1
Prints a help text showing all available options and how to use them.
bash script.sh Asa2_Module_Repo_Cron_Refresh --help
With this option you can limit the result to products of the specified IDs. Multiple IDs can be specified separated by commas (without spaces!).
bash script.sh Asa2_Module_Repo_Cron_Refresh id=254,636,4986
lifetime option to only include items with a last refresh time older than the defined lifetime in seconds. Default is 86400 (one day).
For example, if you want to use the cronjob to only update products older than two hours, use a lifetime of 7200.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200
Limits the amount of products to be updated. Default is 20.
If this option is not used, the limit is automatically set to 20.
Example to raise the limit:
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50
If you know what you are doing, you can turn off the limit with
Working without a limit may not be beneficial if you have a lot of products in use, as the job could then load the system for a longer period of time.
Example to disable the limit:
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=-1
Activates the cronjob log. This will write the cronjob results to a file defined with
If you want to use the
log feature, you must define a directory path. It must be writable. ASA2 will create a log file asa2reporefresh.log there. Using a log rotate function new files will be created when the old reaches 20MB.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200 --log --logpath=/home/me/tmp/asa2
Can be used to insert a fixed pause of the specified seconds between two API requests. This may help to avoid the RequestThrottled API issue.
// inserts a pause of 2 seconds between API requests bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=3 --pause=3 --verbose
php option, you can tell the ASA2 cronjob what PHP executable it should use to execute the command. With some webhosters the standard command “php” executes an outdated version and there is a special command for each version, e.g. “php73” or “php74”.
Please check which PHP version is required for the use of ASA2 here: https://bit.ly/asa2-php-version
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --php=php74
With this option you can limit the result to products of shop specified by the IDs. Multiple IDs can be specified separated by commas (without spaces!).
bash script.sh Asa2_Module_Repo_Cron_Refresh shop_id=302,412
tag option to filter the results by tag slug. You can define multiple tags as comma separated list.
For example, only update products with tag slug “green” and “sale”.
bash script.sh Asa2_Module_Repo_Cron_Refresh tag=green,sale
You can combine the
tag options. For example, only update repo items from category 31 and 40 with tag slug “green” and “sale”:
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40 tag=green,sale
verbose option to get more information about the updated products.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200 --verbose