PHP code example of akki-io / cron-expression-generator

1. Go to this page and download the library: Download akki-io/cron-expression-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akki-io / cron-expression-generator example snippets


    use AkkiIo\CronExpressionGenerator\CronExpressionGenerator;

    $options = [];

    $cronExpression = (new CronExpressionGenerator($options))->generate();

    $options = [];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // * * * * *

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 0,
        ],
        'hour' => [
            'type' => 'EVERY',
            'every' => 1,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 0 */1 * * *

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 15 10 * * *

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_week' => [
            'type' => 'RANGE',
            'start' => 1,
            'end' => 5,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 15 10 * * 1-5

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_month' => [
            'type' => 'ONCE',
            'at' => 22,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 22 * *

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_week' => [
            'type' => 'ONCE',
            'at' => 0,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 * * 0

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_month' => [
            'type' => 'ONCE',
            'at' => 22,
        ],
        'month' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 22 10 *