PHP code example of qrotux / phalcon-cron

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

    

qrotux / phalcon-cron example snippets


$di = new \Phalcon\Di();

// ...

$console = new \Phalcon\Cli\Console();

// ...

$di->setShared("console", $console);

// ...

$console->handle($arguments);

$di->set(
	"cron",
	function () {
		$cron = new \Sid\Phalcon\Cron\Manager();
		
		$cron->add(
			new \Sid\Phalcon\Cron\Job\Callback(
				"* * * * *",
				function () {
					// ...
				}
			)
		);
		
		$cron->add(
			new \Sid\Phalcon\Cron\Job\Phalcon(
				"0 * * * *",
				[
					"task"   => "task",
					"action" => "action",
					"params" => "params"
				]
			)
		);
		
		$cron->add(
			new \Sid\Phalcon\Cron\Job\System(
				"* 0 * * *",
				"sh backup.sh"
			)
		);
		
		return $cron;
	}
);

class CronTask extends \Phalcon\Cli\Task
{
	public function mainAction()
	{
		$this->cron->runInBackground();
	}
}

$datetime = new \DateTime("2015-01-01 00:00:00");

$cron->getDueJobs($datetime);

$datetime = new \DateTime("2015-01-01 00:00:00");

$cron->runInBackground($datetime);

$cron = new \Sid\Phalcon\Cron\Manager();

$cron->addCrontab("/path/to/crontab");

$crontab = new \Sid\Phalcon\Cron\CrontabParser("/path/to/crontab");

$jobs = $crontab->getJobs();

* * * * * /usr/bin/php /path/to/cli.php cron

* * * * * /usr/bin/php /path/to/cli.php cron