Distributed Cron Worker

Distributed Cron Worker

README

Distributed Cron Daemon with PHP

Requirements

  • PHP 7.0+
  • aws/aws-sdk-php
  • mtdowling/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 TeknasyonCrondLockerMemcachedLocker or TeknasyonCrondLockerRedisLocker
  • Create TeknasyonCrondDaemon with cron config and Locker class
<?php

use TeknasyonCrondLockerRedisLocker;
use TeknasyonCrondDaemon;

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

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

// ...

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *