teknasyon/crond

Distributed Cron Worker

2.0.1 2023-01-19 13:52 UTC

This package is auto-updated.

Last update: 2024-10-19 17:43:03 UTC


README

Distributed Cron Daemon with PHP

Requirements

  • PHP 8.0+
  • aws/aws-sdk-php
  • dragonmantank/cron-expression
  • psr/log

Usage

  • Set your cron config,
$crons = [
    'my_cron_id1' => [
        'expression' => '* * * * *',
        'cmd' => '/usr/bin/php /pathto/myproject/mycron.php',
        'lock' => 0 //No need lock
    ],
    'my_cron_id2' => [
        'expression' => '*/10 * * * *',
        'cmd' => '/usr/bin/php /pathto/myproject/minutecron.php',
        'lock' => 1
    ],
    'my_cron_id2' => [
         'expression' => '* * * * *',
         'cmd' => '/usr/bin/php /pathto/myproject/infinitecron.php' // Like lock:1
    ]
]
  • Create your Locker class \Teknasyon\Crond\Locker\MemcachedLocker or \Teknasyon\Crond\Locker\RedisLocker
  • Create \Teknasyon\Crond\Daemon with cron config and Locker class
<?php

use Teknasyon\Crond\Locker\RedisLocker;
use Teknasyon\Crond\Daemon;

try {
$crond = new Daemon($cronConfig, $locker);
$crond->setLogger($myPsrLoggerInterfacedObj);
$crond->start();

} catch (\Exception $e) {
    //Error handling
}

// ...