Skip to content

4. Cron setup

Hourly/Daily Cron and Queue processing

YouDate requires three CRON commands: two for common tasks (hourly, daily) and one for queue processing.

Cron setup on Ubuntu/Debian

To setup cron commands on Ubuntu/Debian, read this answer:

Cron commands for hourly/daily tasks and queue processing are:


These paths are examples, you should specify the correct path to the script

30 * * * * /path/to/youdate/application/yii cron/hourly >/dev/null 2>&1
0 18 * * * /path/to/youdate/application/yii cron/daily >/dev/null 2>&1               
* * * * * /path/to/youdate/application/yii queue/run --isolate=0 >/dev/null 2>&1               

Some hosting providers are not allowing to use cron commands properly. Instead of this, they allow running cron commands using wget.

For this case, you can use a file named cron.php (see below). Also you should update your .env config file: CRON_SECRET param must be set. Example: CRON_SECRET is set to mysecret, so the cron command will look like this:

30 * * * * /path/to/usr/bin/wget -O /dev/null https://youdate.local/cron.php?action=cron/hourly&secret=mysecret
0 18 * * * /path/to/usr/bin/wget -O /dev/null https://youdate.local/cron.php?action=cron/daily&secret=mysecret
* * * * * /path/to/usr/bin/wget -O /dev/null https://youdate.local/cron.php?action=queue/run&secret=mysecret

require(__DIR__ . '/application/bootstrap.php');
require(__DIR__ . '/application/vendor/autoload.php');
require(__DIR__ . '/application/environment.php');
require(__DIR__ . '/application/vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/application/config/console.php');
$application = new yii\console\Application($config);

// protect with password
if (env('CRON_SECRET') !== false) {
    $secret = $_GET['secret'] ?? null;
    if ($secret !== env('CRON_SECRET')) {
        die("Access denied");
} else {
    die("CRON_SECRET key required (.env file). See for more details");

$action = isset($_GET['action']) ? $_GET['action'] : null;
$availableCommands = ['cron/hourly', 'cron/daily', 'queue/run'];

// when pcntl_signal function is not allowed
Yii::$container->set(\yii\queue\db\Command::class, ['isolate' => false]);

if (in_array($action, $availableCommands)) {
} else {
    die("$action not supported");

Then you need to execute this script periodically. For example, you can use EasyCron for this.

Detailed documentation located here:

It's better to process queue with Supervisor or Systemd.

For more details visit official yii2-queue module docs.

Example config for Supervisor (/etc/supervisor/conf.d/youdate.conf):

command=/usr/bin/php /home/youdate/public_html/application/yii queue/listen --verbose=1 --color=0