PHP code example of jenner / crontab

1. Go to this page and download the library: Download jenner/crontab 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/ */

    

jenner / crontab example snippets



$missions = [
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
];

$tasks = array();
foreach($missions as $mission){
    $tasks[] = new \Jenner\Crontab\Mission($mission['name'], $mission['cmd'], $mission['time'], $mission['out']);
}

$crontab_server = new \Jenner\Crontab\Crontab(null, $tasks);
$crontab_server->start(time());

$missions = [
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
];

$daemon = new \Jenner\Crontab\Daemon($missions);
$daemon->start();

function task_loader() {
    $missions = [
        [
            'name' => 'ls',
            'cmd' => "ls -al",
            'out' => '/tmp/php_crontab.log',
            'time' => '* * * * *',
            'user' => 'www',
            'group' => 'www'
        ],
        [
            'name' => 'ls',
            'cmd' => "ls -al",
            'out' => '/tmp/php_crontab.log',
            'time' => '* * * * *',
            'user' => 'www',
            'group' => 'www'
        ],
    ];

    return $missions;
}

$daemon = new \Jenner\Crontab\Daemon();
$daemon->registerTaskLoader("task_loader");
$daemon->start();

$missions = [
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'err' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
        'user' => 'www',
        'group' => 'www'
    ],
];

$http_daemon = new \Jenner\Crontab\HttpDaemon($missions, "php_crontab.log");
$http_daemon->start($port = 6364);
shell
* * * * * php demo.php