Scheduled tasks: cronjobs
This page is for developers who declare scheduled tasks in code ($schedule->command()->hourly(), #[AsCronTask],
Celery beat, @Scheduled). In Exponential, scheduled work is grouped into cronjob parts declared in
settings/cronjob.ini; the system's crontab runs php runcronjobs.php <part> at the rhythm each part needs. The
schedule itself lives in the crontab, not in code (Cronjobs for applications).
Contents
- Parts and scripts
- Parts the site needs
- Adding your part
- Running and scheduling
- Locks, pauses and watching
- Compared with other frameworks
Parts and scripts
| Block | Holds |
|---|---|
[CronjobSettings] Scripts[] | the global part (run when no part is named) |
[CronjobSettings] ExtensionDirectories[] | extensions that have a cronjobs/ directory |
[CronjobPart-<name>] Scripts[] | a named part |
eZRunCronjobs (kernel/classes/ezruncronjobs.php) runs a script; the code of a kernel part is an
Exponential\Runnable\CronjobPart class in kernel/private/classes/cronjobs/
(Cronjobs).
Parts the site needs
Shipped parts include frequent (notification, workflow, content jobs, audit) and infrequent (basket cleanup, link
check, mail preferences), among others. Without frequent, notifications are not sent and content waiting in a
deferred workflow never publishes. Schedule them in every installation (Cronjobs guide).
Adding your part
# extension/expdemo/settings/cronjob.ini.append.php
[CronjobSettings]
ExtensionDirectories[]=expdemo
[CronjobPart-expdemo]
Scripts[]=expdemo_import.php
*/ ?>The script lives in extension/expdemo/cronjobs/expdemo_import.php (Writing a cronjob script).
A part of your own can be scheduled separately from the kernel's.
Running and scheduling
php runcronjobs.php --list --allow-root-user
php runcronjobs.php -s site expdemo --allow-root-user
php bin/php/console cron:expdemo -s site*/5 * * * * cd /path/to/installation && php runcronjobs.php -q -s site frequent >> var/log/cron-frequent.log 2>&1
15 * * * * cd /path/to/installation && php runcronjobs.php -q -s site expdemo >> var/log/cron-expdemo.log 2>&1Run as the web server's user, never as root. -s <siteaccess> matters when your extension is active only in some
siteaccesses. Setup > Cronjobs proposes crontab lines.
Locks, pauses and watching
- Only one instance of a cronjob script runs at a time;
MaxScriptExecutionTimelets a new instance take over a stuck one. - Parts can be paused in Setup > Cronjobs; a paused part is skipped whoever starts it (Pausing cronjob parts).
- Setup > Cronjobs shows each part, its last runs, output and issues (Cronjobs console).
- Make scripts safe to run twice and to be interrupted.
Velocity has a scheduler of its own for handlers of its application layer; it does not run Exponential's cronjob scripts, so keep the system crontab for them (Velocity scheduler).
Compared with other frameworks
| Framework | Concept | Exponential |
|---|---|---|
| Laravel | schedule:run every minute, schedule in code | one crontab line per part, parts in INI |
| Symfony | Scheduler component, recurring messages | cronjob parts; recurring jobs can enqueue expqueue jobs |
| Django, Celery | management commands from cron, Celery beat | cronjob parts |
| Rails | whenever, Solid Queue recurring tasks | cronjob parts |
| Spring | @Scheduled | cronjob parts |
Related pages
- Queues and background jobs
- Cronjob part filter
- Runnable commands, cronjob parts and views
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.