PHPackages                             qrotux/phalcon-cron - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. qrotux/phalcon-cron

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

qrotux/phalcon-cron
===================

Cron component for Phalcon.

0.2.1(7y ago)037MITPHPPHP &gt;= 5.6

Since Feb 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/qrotux/phalcon-cron)[ Packagist](https://packagist.org/packages/qrotux/phalcon-cron)[ RSS](/packages/qrotux-phalcon-cron/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

Sid\\Phalcon\\Cron
==================

[](#sidphalconcron)

Cron component for Phalcon.

[![Build Status](https://camo.githubusercontent.com/ae4267a83330043e6ba78020c1986d10ed243e093b5a64073ad12f4ea958a518/68747470733a2f2f7472617669732d63692e6f72672f536964526f62657274732f7068616c636f6e2d63726f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/SidRoberts/phalcon-cron)[![Build Status](https://camo.githubusercontent.com/26886cc011780404795533187a0dac73628d499b9184fa5f5495944f50c6efc4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536964526f62657274732f7068616c636f6e2d63726f6e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SidRoberts/phalcon-cron/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1b3e484e365fd60552ff3b260e48e6bc85a401d2e342c09b106dc3bb3cf697e7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536964526f62657274732f7068616c636f6e2d63726f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SidRoberts/phalcon-cron/?branch=master)[![Code Climate](https://camo.githubusercontent.com/e95c73503087f600f278e334f0efedebe7810cd171d71f253eae579240fc615b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f536964526f62657274732f7068616c636f6e2d63726f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/SidRoberts/phalcon-cron)[![Test Coverage](https://camo.githubusercontent.com/0fd7334c1ed1d912c8552e6980f9d91f1b2695cf2e6051ae9adfb89b9efae326/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f536964526f62657274732f7068616c636f6e2d63726f6e2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/SidRoberts/phalcon-cron/coverage)

Installing
----------

[](#installing)

Install using Composer:

```
{
	"require": {
		"sidroberts/phalcon-cron": "dev-master"
	}
}
```

You'll also need to add the `console` to the DI:

```
$di = new \Phalcon\Di();

// ...

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

// ...

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

// ...

$console->handle($arguments);
```

Example
-------

[](#example)

### Crontab

[](#crontab)

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

```

### DI

[](#di)

```
$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;
	}
);
```

### CLI Task

[](#cli-task)

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

Foreground Versus Background
----------------------------

[](#foreground-versus-background)

Running jobs in the foreground (sequential):

```
Job1 -------->
Job2          ----------------->
Job3                            ---->

```

Running jobs in the background (parallel):

```
Job1 -------->
Job2 ----------------->
Job3 ---->

```

For most applications it is recommended to use `->runInBackground()` as this is typical of a Cron implementation and is often quicker. If you specifically need to access the output of each Cron Job, use `->runInForeground()`.

`->runInBackground()` returns an array of Process instances. `->runInForeground()` returns an array of outputs.

Waiting, Terminating And Killing
--------------------------------

[](#waiting-terminating-and-killing)

By default all background processes register a [shutdown function](http://php.net/manual/en/function.register-shutdown-function.php) that forces the PHP script to wait for job to complete before shutting down. You can call `->wait()` on a Process instance if you need to wait until it has finished.

You can also use `->terminate()` and `->kill()` on a Process to send terminate and kill signals.

`->wait()`, `->terminate()` and `->kill()` are also available on the Manager instance and will wait for, terminate or kill every process.

Running Jobs At A Custom Time
-----------------------------

[](#running-jobs-at-a-custom-time)

You can see which Jobs are due at a particular time by passing a `\DateTime` to `->getDueJobs()`:

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

$cron->getDueJobs($datetime);
```

You can also pass a \\DateTime to `->runInForeground()`/`->runInBackground()` to run jobs due at that particular time.

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

$cron->runInBackground($datetime);
```

### Adding Jobs From A Crontab

[](#adding-jobs-from-a-crontab)

You can also add jobs from a Crontab file, such as this one:

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

```

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

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

To get an array of System Job instances from the Crontab:

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

$jobs = $crontab->getJobs();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~705 days

Total

3

Last Release

2683d ago

PHP version history (2 changes)v0.1PHP &gt;= 5.4

0.2.1PHP &gt;= 5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12318929?v=4)[qrotux](/maintainers/qrotux)[@qrotux](https://github.com/qrotux)

---

Top Contributors

[![SidRoberts](https://avatars.githubusercontent.com/u/1364214?v=4)](https://github.com/SidRoberts "SidRoberts (23 commits)")[![hgati](https://avatars.githubusercontent.com/u/6913728?v=4)](https://github.com/hgati "hgati (2 commits)")[![qrotux](https://avatars.githubusercontent.com/u/12318929?v=4)](https://github.com/qrotux "qrotux (1 commits)")

###  Code Quality

TestsCodeception

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/qrotux-phalcon-cron/health.svg)

```
[![Health](https://phpackages.com/badges/qrotux-phalcon-cron/health.svg)](https://phpackages.com/packages/qrotux-phalcon-cron)
```

###  Alternatives

[mult1mate/cron-manager

Flexible cron tasks manager for MVC-type applications

40338.5k3](/packages/mult1mate-cron-manager)[ttree/scheduler

Simple task scheduler for Neos Flow Framework

21108.8k1](/packages/ttree-scheduler)[webtoolsnz/yii2-scheduler

A scheduled task runner for Yii2 applications

1881.1k](/packages/webtoolsnz-yii2-scheduler)[pmill/php-scheduler

Simple PHP task scheduler

1833.5k](/packages/pmill-php-scheduler)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
