# Scheduled Tasks
DreamFactory does not natively support scheduled tasks but you can setup a CRON job for this purpose. Let's create an example that calls an API every minute of the day.
# Creating the Script
First we will create the script to call the API. One easy way to do so is by navigating to the
API Docs tab and copying the cURL command for the appropriate call we would like to make. In this case we have business logic attached to
_table/employees that is synchronizing data between two databases.
Once we have the cURL command we can convert it to PHP by using this useful tool. After we will create a file named
cron.php in the
public folder containing the generated PHP code.
# Running the CRON job
To start let's define the CRON job parameters:
* * * * * /usr/bin/php /opt/dreamfactory/public/cron.php >/dev/null 2>&1
This can be broken into 4 parts, the timing, execute PHP, path to script, and the output. In this example the
* * * * * means it will run once every minute. The second portion is the path to PHP to allow it to be executed. The important part is now providing the full path to the file you would like to run. Finally you can write the output to a file or discard it, in this case I have set it to be discarded. If you would like to learn more about the structure, check out this article.
Next you will edit the
crontab by running the following:
$ crontab -e
You will be put into the text editor where you can simply paste in your CRON job and save it. Now you have a scheduled task running every minute to call your API!