Configuring cron jobs

Alex Tselegidis

Following up our previous article about using the available Easy!Appointments console commands, today we will take a closer look on how to schedule some of them to automatically run based on a predefined schedule.

Cron Jobs (or Scheduled Tasks on Windows) are time-based scheduled jobs that are executed on predefined intervals or specific time during a day. Typically they automate maintenance and administration tasks although they can be used in many different ways.

The most common use cases for an Easy!Appointments installation are the automation of the Google Calendar Synchronization feature and the automated database backups.

Configuring On Linux/Mac

In order to use Cron Jobs on a Linux/Mac environment, you will need to open the crontab utility from the terminal.

crontab -e

This will open the predefined editor that you can use to add cron based commands. Each line represents a different scheduled task and you can add as many as you need. For Backup and Google Calendar Sync jobs that run every hour, we will need to add the following commands.

0 * * * * /usr/bin/php /path/to/easyappointments/index.php console backup
0 * * * * /usr/bin/php /path/to/easyappointments/index.php console sync

The first “0 * * * *” part configures the command to run every hour (0 minutes * hours * days etc). The second part is the command that will be executed (make sure you change the path to the index.php file with your own).

There are user friendly tools online that can generate the crontab line for you:

Configuring On Windows

Windows have a slightly different way to define scheduled tasks than Unix-like systems.

Open The Task Scheduler

  • Open the start menu
  • Search for “Task Scheduler”
  • Open the app (if you have permission problems then try running it as an administrator)

Create A New Task

  • Click on “Create Task”
  • Add an appropriate name for the task (e.g. “EasyAppointments Sync”)
  • Go to the “Triggers” tab and add a new trigger
  • Set the task to daily, every hour
  • Go to the “Actions” tab and add a new action
  • Set the path to your “php.exe” file (e.g. “E:\xampp\php80\php.exe”)
  • Set the “Start in” option to your Easy!Appointments installation path
  • Add the path to the “index.php console sync” in the Arguments field
  • Now save the scheduled task and wait till it’s first execution

There are plenty of online tutorials about how to configure scheduled tasks on Windows in case you need additional information. You can get started with this Medium post about configuring a PHP Cron in Windows.

More great articles

software-code-testing

Contributing to release testing rounds

Soon enough, the Easy!Appointments 1.5 development phase will be completed and the first pre-release packages will become available for download.…

Read Story
coding-illustration

Best practices on code refactoring

Find out all the best practices of code refactoring and how to apply them correctly on your own project.

Read Story
Default Featured Image

How to submit feature requests

Easy!Appointments is an open source project and thus user feedback is very important for the development progress. Submissions proposing new killer-features or required…

Read Story

Never miss a minute

Get great content to your inbox every month. No spam.

    Only great content, we don’t share your email with third parties.
    Arrow-up