PHP code example of pe / component-cron

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

    

pe / component-cron example snippets


use PE\Component\Cron\Crontab;
use PE\Component\Cron\Job;

// Instantiate with default binary path
$crontab = new Crontab();

// Or instantiate with custom binary path
$crontab = new Crontab('/usr/sbin/crontab');

// Get all jobs
$crontab->all();// returns array of Job instances

// Create new job from string
$job = Job::fromString('*/5 * * * * command');

// Or create programmatically
$job = (new Job())->setMinute('*/5')->setCommand('command');

// Add job
$crontab->add($job);

// Get job by index
$job = $crontab->get(0);

// Remove job by index
$crontab->remove(0);