Skip to content

bgmorton/courier-cron

Repository files navigation

Examples of Scheduling Courier Notifications in PHP

This repository contains examples on how the Courier notification platform can be used with PHP for sending scheduled notifications.

Requirements

This project requires the following packages, installed via composer

You can install all of this in your own project by running:

composer require crunzphp/crunz vlucas/phpdotenv trycourier/courier guzzlehttp/guzzle

If you are cloning this repository, run the following to install these dependencies from the included coomposer.json file:

composer install

Crunz is used for scheduling in this app, and it has its own extensive documentation. The most important bit is adding it to the crontab on your server - once this is done, all task handling is handled from within your PHP app, no need to add additional cron jobs:

* * * * * cd /path/to/project && vendor/bin/crunz schedule:run

Tasks

Crunz tasks must be created in the ./tasks directory, and end with Tasks.php.

Crunz requires a configuration file be present, containing a configured timezone. Create this by running:

vendor/bin/crunz publish:config

You can confirm tasks are present by running:

vendor/bin/crunz schedule:list

This will output a table containing your scheduled tasks:

+---+------------------------------+-------------+-----------------+
| # | Task                         | Expression  | Command to Run  |
+---+------------------------------+-------------+-----------------+
| 1 | Sending scheduled email      | 30 13 1 6 * | object(Closure) |
| 2 | Sending recurring email      | 30 13 * * * | object(Closure) |
| 3 | Sending scheduled automation | 30 13 1 6 * | object(Closure) |
+---+------------------------------+-------------+-----------------+

For testing, you can force all tasks to run immediately:

vendor/bin/crunz schedule:run --force

For more about tasks, including calling external PHP functions and logging the results for debugging, check out the Crunz documentation.

Courier

This example app uses the Courier PHP SDK to send notifications using Courier.

The credentials for Courier must be supplied in the .env file which can be created by duplicating the template file:

cp .env.example .env

...and then filling out the require details.

The following must also be configured on the Courier Side: Templates, Recipients, and Brands. Each of these will have their own unique ID which is used by the Courier SDK and can should be added to the .env file.

Using Laravel?

There's no need to use Crunz if you're using Laravel - it already has scheduling built in.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages