Cronjobs for applications
This page is for application creators whose application has periodic work: imports, reminders, cleanups, reports. Exponential runs such work as cronjob parts: named groups of scripts that the system crontab starts. The administrator's guide is Cronjobs.
Contents
Parts and scripts
settings/cronjob.ini:
| 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 |
Shipped parts include frequent (notification, workflow, content jobs, audit), infrequent (basket cleanup, link
check, mail preferences), contentjobs, audit, unlock, cleanuprss and cache_cleanup
(Commands: cronjob parts).
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).
Add it to an existing part only when it is quick and has the same rhythm; a part of your own can be scheduled
separately.
Running parts
php runcronjobs.php --list --allow-root-user
php runcronjobs.php -s site expdemo --allow-root-user
php runcronjobs.php -s site --script=expdemo_import.php --allow-root-user
php bin/php/console cron:expdemo -s site-s <siteaccess> matters when your extension is active only in some siteaccesses (ActiveAccessExtensions[]): the
script is not found otherwise.
The crontab
*/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. php bin/php/console crontab:list shows the current crontab; Setup >
Cronjobs proposes lines (12. Scheduling with the crontab).
Locks, pauses and time limits
- Only one instance of a cronjob script runs at a time.
MaxScriptExecutionTime(default 43200 seconds) lets a new instance take over a stuck one; set it per part for long jobs. - Parts can be paused in Setup > Cronjobs (
[PauseSettings] Pause=enabled); a paused part is skipped whoever starts it (Pausing cronjob parts). - Make scripts safe to re-run: a crashed run is followed by another.
Watching them
Setup > Cronjobs shows each part, its last runs, output and issues, and whether the crontab schedules it (Cronjobs console). Write clear output lines; they are what an administrator reads when something fails.
Related pages
- Writing a cronjob script
- Background work: queues, cronjobs and content jobs
- Cronjob examples (
doc/eng-us/examples/cronjobs/) - 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.