PHP code example of xfra35 / f3-cron

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

    

xfra35 / f3-cron example snippets


//index.php
$f3=:instance();
$cron->set('Job1','App->job1','@daily');
$cron->set('Job2','App->job2','@weekly');
...
$f3->run();

$cron->set('Job1','App->job1','* * * * *'); // runs every minute
$cron->set('Job2','App->job2','*/5 * * * *'); // runs every 5 minutes
$cron->set('Job3','App->job3','0 8 * * 1'); // runs every Monday at 08:00
$cron->set('Job4','App->job4','0 4 10 * *'); // runs the 10th of each month at 04:00
$cron->set('Job5','App->job5','0 0 * */3 *'); // runs on a quarterly basis

$cron->preset('weekend','0 8 * * 6'); // runs every Saturday at 08:00
$cron->preset('lunch','0 12 * * *'); // runs every day at 12:00
$cron->set('Job6','App->job6','@weekend');
$cron->set('Job7','App->job7','@lunch');

$cron->script='htdocs/index.php';//relative to app root
$cron->script=__DIR__.'/cron.php';//absolute path

$cron->binary('/home/myphp-cli');

$cron->binary('/home/myphp-cli',TRUE); // set PHP binary path, whether it's valid or not

//index.php
$f3=on.ini');
Cron::instance(); // <--- MANDATORY
$f3->run();

$cron = Cron::instance();

$cron->log=TRUE;// enable logging

$cron->web=TRUE;// enable web interface

$cron->script='htdocs/index.php';//relative to app root
$cron->script=__DIR__.'/cron.php';//absolute path

echo $cron->binary;// php

$cron->binary('/home/myphp-cli'); // set PHP binary path, only if it's valid
$cron->binary('/home/myphp-cli',TRUE); // set PHP binary path, whether it's valid or not

$cron->silent=FALSE;

$cron->set('Job1','App->job1','@daily'); // runs daily
$cron->set('Job2','App->job2','*/5 * * * *'); // runs every 5 minutes
$cron->set('Job3','App->job3','0 8 * * 1'); // runs every Monday at 08:00

$cron->preset('weekend','0 8 * * 6'); // runs every Saturday at 08:00
$cron->preset('lunch','0 12 * * *'); // runs every day at 12:00

$cron->isDue('Job3',time()); // returns TRUE if Job3 is due now

$cron->execute('Job2',FALSE); // executes Job2 synchronously

$cron->run(strtotime('yesterday midnight'));
// run asynchronously all jobs due yesterday at midnight
cron
* * * * * cd /path/to/app; php index.php /cron
ini
[CRON]
binary = /path/to/php, TRUE
cron
* * * * * cd /path/to/app; flock -n cron.lock php index.php /cron