PHP code example of tiben / crontab-manager

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

    

tiben / crontab-manager example snippets

 {.php}
    $crontabJob = new CrontabJob();
    $crontabJob
        ->setMinutes(30)
        ->setHours(23)
        ->setDayOfMonth('*')
        ->setMonths('*')
        ->setDayOfWeek('*')
        ->setTaskCommandLine('df >> /tmp/df.log')
        ->setComments('Logging disk usage'); // Comments are persisted in the crontab
    
 {.php}
    $crontabJob = CrontabJob::createFromCrontabLine('30 23 * * * df >> /tmp/df.log');
    
 {.php}
$crontabRepository->addJob($crontabJob);
$crontabRepository->persist();
 {.php}
$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$crontabJob = $results[0];
$crontabJob->setHours(21);
$crontabRepository->persist();
 {.php}
$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$crontabJob = $results[0];
$crontabRepository->removeJob($crontabJob);
$crontabRepository->persist();
 {.php}
$crontabJob->setEnabled(false);