Cronjob Setup



ASA2’s cronjobs can be executed via the bash script in the plugin subdirectory “scripts”.

Execution syntax:

bash [wp_path]/wp-content/plugins/amazon-simple-affiliate/scripts/ [name] [options]

To be replaced:

  • [wp_path] with the local server path of your WordPress installation

  • [name] with the internal cronjob name which can be found on the respective page of the cronjobs

  • [options] with a list of options which are documented on the respective page of the cronjobs (optional)


  • must be executable

  • You must know the server-side path to

The info box “Cronjobs” in the “Service” subsection will help you to collect information about these requirements.

ASA2 cronjob infobox


The upper area of the infobox shows whether is executable on your server, which is a prerequisite for running the cronjob.

Note must be executable to be able to run the server-side cronjob

If it shows as not executable, click the link that tries to fix that. If this does not work, you can do this manually with the following shell command:

// in amazon-simple-affiliate/scripts/
chmod 0755

Path to

In the lower part of the info box you will see the path to the on your server including a sample execution. You can copy this path for the configuration on your server which is described in more detail below.


If you have SSH access to your server and the right to setup cronjobs, you can use the command crontab -e on the shell.

Replace [wp_path] with the local server path of your WordPress installation.

0/3 * * * * /[wp_path]/wp-content/plugins/amazon-simple-affiliate/scripts/ Asa2_Cron_Ratings

This is a good tutorial about cronjobs: Scheduling Tasks with Cron Jobs

Webhosting Control Panel

Many web hosting companies provide control panels for their customers. If you are one of them, you might be able to find a section in your control panel to manage your cron jobs.

Cronjob panel 1 Cronjob panel 2


Using ASA2’s Cron REST API allows you to execute the cronjobs via URL. This option was introduced because some web hosts support running cronjobs only by URL and unfortunately not at shell level.


Before you can use the Cron REST API, you need to activate it via the option “Cron REST API” in ASA2’s options section “Advanced”.

Option Cron REST API


For ASA2 to accept the URL to run a cronjob, a token unique to your installation must be present as a parameter in the URL. This must consist of alphanumeric characters and can be entered in the “Cron REST API Token” field. It is recommended to use the button “Generate new token” to create a random token.

Option Cron REST API token

URL Syntax

  • [site-domain] is the domain of your website, e.g.

  • [wp-api-path] is “wp-json” by default (see Routes and Endpoints)

  • [cronjob-endpoint] depends on the cronjob you want to run. Every ASA2 cronjob has its own endpoint name, which you can find in the “REST API Endpoint” section of the respective page:

  • [token] must be the token you configured as explained in Token

  • [options] can be a list of options that are supported by the cronjob in URL parameter syntax, e.g. &limit=3&cat=32,42


To run the product update cronjob with a limit of 10 products, category and lifetime filter, the URL would look like this:[your-token]&limit=10&cat=31,40&lifetime=7200

To run the ratings cronjob with a quantity setting of 5, this is the URL:[your-token]&quantity=5


If you do not have access to real server-side cronjobs on your webserver, WP Cron API might be an alternative. However, the use of server-side cronjobs is highly recommended as the WP Cron API is executed on visitor accesses. But this is exactly what we want to avoid when using cronjobs.


Using the WP Cron API can affect the loading speed of your site. Server-side are therefore highly recommended!

Add Cron Schedule

In this example the plugin WP Crontrol is used for the setup.

For this example we want to run a cronjob every 3 minutes. So we have to configure an interval of 3 minutes for the WP Cron API if this is not already available.

After you have installed and activated the plugin WP Crontrol, open the section “Settings / Cron Schedules” and enter the new cron schedule, in this case 180 seconds for 3 minutes.

ASA2 WP Cron API interval

Using the Cron Wrapper


The “Cron Wrapper” is a PHP helper class that allows you to run any ASA2 cronjob. During initialization it only expects the name of the cronjob, which you can find on the pages of the respective cronjob. In this example, we use the Product Update Cronjob, so the name is Asa2_Module_Repo_Cron_Refresh.


Replace the name Asa2_Module_Repo_Cron_Refresh with the cronjob name of your choice.

$cronWrapper = new \Asa2\Cron\Wrapper('Asa2_Module_Repo_Cron_Refresh');


If desired or necessary, you can also define options for the execution of the cronjob. A list of all options can also be found on the page of the respective cronjob.

    'limit' => 3,
    'cat' => '31,40'


Finally, the cronjob can be executed.



So, putting it all together, the code for using the Cron Wrapper looks like this:

$cronWrapper = new \Asa2\Cron\Wrapper('Asa2_Module_Repo_Cron_Refresh');
    'limit' => 3,
    'cat' => '31,40'

Add Cron Event

To use the Cron Wrapper together with WP Crontrol, open section “Tools / Cron Events” and click the tab “Add PHP Cron Event”. Enter the code discussed above (see Summary) into the field “PHP Code” and adjust it according to your needs.

ASA2 WP Cron API PHP event

After saving the cron event, you will see it in the list of WP-Cron Events. The “Next Run” column displays the time of the next execution of the job. From now on, the function for updating products runs regularly at the configured intervals.

ASA2 WP Cron API list

To get details about the result of a job, see the cronjob_repo_refresh_debugging section.


To get information from the execution of a cronjob, you can enable the option Log Cronjobs in the section “Options / Logging”.

Then you get an entry in the “Log” area for each cronjob execution. If you move your mouse over an entry, the link “Details” will appear, which opens a popup with further details.

ASA2 Cronjob logging