PHPackages                             makinacorpus/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. makinacorpus/cron

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

makinacorpus/cron
=================

Simple applicative cron API

1.0.1(2y ago)04GPL-2.0-or-laterPHPPHP &gt;=8.0

Since May 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/makinacorpus/php-cron)[ Packagist](https://packagist.org/packages/makinacorpus/cron)[ RSS](/packages/makinacorpus-cron/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (3)Used By (0)

Applicative cron task runner
============================

[](#applicative-cron-task-runner)

Simple applicative cron task implementation.

How it works:

- You as the library user register callables as being cron tasks, using a descriptive attribute.
- It can be any callable, a function, an anonymous function, an instance method, a class static method or an invokable class instance.
- You need to setup a system cron entry for running the applicative cron, depending upon your framework, using Symfony a CLI command is provided. This tick must run very often, such as every minute.
- When the cron runs, for each registered task, it checks its schedule againsts the current sytem date.
- For each matching schedule, it checks first for the configured minimum delay between two run and excludes tasks which have been run too recently.
- For each remaining non excluded task, it runs it, and store the latest run data long error message and error trace if any error occured.

Simply put, it takes a task list, test each task schedule against current date, and run it when it matches.

State is per default kept in memory during runtime, then discarded. Future implementations will allow you to store it within PDO and maybe other backends.

State when persisted allows the user to change task schedule without changing the code. Schedule is always stored as a raw string which allows alternative implementations to exist.

Default schedule implementation accepts incomplete POSIX cron expression but only with single digit values. An alternative implementation can use `dragonmantank/cron-expression` for a more complete POSIX cron expression.

Roadmap
=======

[](#roadmap)

- `makinacorpus/goat-query` state store implementation,
- `PDO` state store implementation,
- unit test Symfony integration,
- logging using `psr/log` everything everywhere,
- add scheduler implementation using `dragonmantank/cron-expression`,
- cron task list and detailed information restitution command,
- meaningful information display via console commands.

How to use
==========

[](#how-to-use)

First, install it:

```
composer require makinacorpus/cron
```

Then proceed with one of the following.

Standalone
----------

[](#standalone)

### Configuring cron tasks

[](#configuring-cron-tasks)

First, create some cron methods:

```
namespace MyVendor\MyApp\Cron;

use MakinaCorpus\Cron\CronTask;

// Using a function.
#[CronTask(id: 'foo', schedule: '1 2 3 4 5')]
function foo(): void
{
    // Do something.
}

// Using an invokable class.
#[CronTask(id: 'bar', schedule: '@daily')]
class Bar
{
    public function __invoke(): mixed
    {
        // Do something.
    }
}

// Using an instance method.
class Buzz
{
    #[CronTask(id: 'buzz', schedule: '@monthly')]
    public function someMethod(): void
    {
    }
}

// Using a static class method.
class Fizz
{
    #[CronTask(id: 'fizz', schedule: '@weekly')]
    public function someMethod(): void
    {
    }
}
```

Then create a task registry:

```
namespace MyVendor\MyApp\Command;

use MakinaCorpus\Cron\TaskRegistry\ArrayTaskRegistry;
use MyVendor\MyApp\Cron\Bar;
use MyVendor\MyApp\Cron\Buzz;
use MyVendor\MyApp\Cron\Fizz;

$taskRegistry = new ArrayTaskRegistry([
    'MyVendor\\MyApp\\Cron\\foo',
    new Bar(),
    [new Buzz(), 'someMethod']
    [Fizz::class, 'someMethod'],
]);
```

### Running it

[](#running-it)

Then, create a runner and execute it, this is basically the piece of code you need to have in your CLI script that executes the cron:

```
namespace MyVendor\MyApp\Command;

use MakinaCorpus\Cron\CronRunner;

// $taskRegistry is the instance you created upper.

$runner = new CronRunner($taskRegistry);
$runner->run();
```

And that's it.

Per default, schedule is forgiving, you may run this script only every 2 or 3 minutes, cron rules will match in a 5 minutes time span after their due date to avoid missing running them.

Symfony
-------

[](#symfony)

### Installing

[](#installing)

Start by adding the bundle to the `config/bundles.php` file:

```
return [
    // Other bundles.
    MakinaCorpus\Cron\Bridge\Symfony\CronBundle::class => ['all' => true],
];
```

### Configuring cron tasks

[](#configuring-cron-tasks-1)

Create some services that have cron task methods, it can litteraly be any class or service, the only requirement is to set the `CronTask` attribute over the targeted methods:

```
namespace MyVendor\MyApp\Cron;

use MakinaCorpus\Cron\CronTask;

// Using an instance method.
class SomeClassWithCronTaskMethods
{
    #[CronTask(id: 'buzz', schedule: '@monthly')]
    public function someInstanceMethod(): void
    {
    }

    #[CronTask(id: 'buzz', schedule: '@monthly')]
    public static function someStaticMethod(): void
    {
    }
}
```

Using the `makinacorpus/argument-resolver` dependency, considering you installed and configured the provided bundle, your methods can have other services as parameters, they will be injected at runtimme.

Make sure they are services in `config/services.yaml` or via any other service registration method:

```
services:
    MyVendor\MyApp\Cron\SomeClassWithCronTaskMethods:
        autoconfigure: true
```

And that's it.

Usage
=====

[](#usage)

Configuring schedule implementation
-----------------------------------

[](#configuring-schedule-implementation)

### Default implementation

[](#default-implementation)

Default implementation if configuration is left untouched supports incomplete POSIX cron expressions, where parts can only be single digits.

For a lot of applications, this is more than enough.

You don't need to configure anything since this is the default.

### dragonmantank/cron-expression

[](#dragonmantankcron-expression)

First install it:

```
composer require dragonmantank/cron-expression
```

Then, during your application bootstrap, call:

```
use MakinaCorpus\Cron\ScheduleFactoryRegistry;
use MakinaCorpus\Cron\Schedule\CronExpressionScheduleFactory;

ScheduleFactoryRegistry::set(new CronExpressionScheduleFactory());
```

And use this API as you would normally do.

Commands
--------

[](#commands)

Commands are available when using it as a Symfony bundle, but nothing prevents you from setting up and using those outside of the Symfony full stack framework usage.

### Run all cron tasks (that should run every minute)

[](#run-all-cron-tasks-that-should-run-every-minute)

Set this in your system cron, or supervisord, or any other orchestrator application:

```
crontab -e

# Run every minute
* * * * * /symfony/project/path/bin/console cron:run
```

You can run it manually as well:

```
bin/console cron:run
```

### Force run a single cron task

[](#force-run-a-single-cron-task)

Simply call the same command, adding the cron task identifier as first argument:

```
bin/console cron:run my_cron_task_id
```

Task configuration
==================

[](#task-configuration)

Set a minimum interval
----------------------

[](#set-a-minimum-interval)

Write me.

Running tests
=============

[](#running-tests)

Core tests
----------

[](#core-tests)

Simply run PHPUnit:

```
composer install
vendor/bin/phpunit
```

Database related tests will be skipped due to the lack of configuration.

Database related tests
----------------------

[](#database-related-tests)

This uses docker compose for spawning a database environement:

```
cd sys/
./run-test.sh
```

This is experimental, it should work.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

1090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69252826f3a70a19fc5dcefb7ef9d26d465bb300245641abb4dd89d0ec391a66?d=identicon)[pounard](/maintainers/pounard)

![](https://www.gravatar.com/avatar/d21b98752b406528da88850922b1061f39bf72eb2126b413d5c12e275811a40b?d=identicon)[Makina Corpus](/maintainers/Makina%20Corpus)

---

Top Contributors

[![pounard](https://avatars.githubusercontent.com/u/341855?v=4)](https://github.com/pounard "pounard (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[j0k3r/php-readability

Automatic article extraction from HTML

186808.8k6](/packages/j0k3r-php-readability)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)

PHPackages © 2026

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