Download the PHP package mluex/endless-cron-command without Composer
On this page you can find all versions of the php package mluex/endless-cron-command. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mluex/endless-cron-command
More information about mluex/endless-cron-command
Files in mluex/endless-cron-command
Package endless-cron-command
Short Description Extension of wrep/daemonizable-command to easily run endless Symfony commands as cronjobs.
License MIT
Homepage https://github.com/mluex/endless-cron-command
Informations about the package endless-cron-command
Endless Cron Commands for Symfony
This package is a small extension of wrep/daemonizable-command. If no Upstart or systemd are available to set up a daemon, a simple cronjob and Symfony Lock are sufficient to produce an almost similar result.
Detailed information on Daemonizable / Endless Commands
Check out the documentation of wrep/daemonizable-command for more information on how to create endless commands: wrep/daemonizable-command
Installation
composer require mluex/endless-cron-command
Which version to use?
- Version 5.* for Symfony 7 and higher
- Version 4.* for Symfony 6
Usage
1. Configuration
EndlessCronCommands require symfony/lock to ensure that only one instance is executed at a time. Please configure the bundle accordingly in your .env.local, e.g.
⚠️ Make sure to use a lock store that supports expiry! Check the Symfony Lock documentation for more information.
2. Implementation
Create a Symfony command that extends EndlessCronCommand and off you go. Here is a minimal example:
If your command includes Monolog's FingersCrossed Log Handlers, you may want to clear them after every iteration as wrep pointed out in his documentation. EndlessCronCommand provides a method for this:
3. Cronjob setup
Add a cronjob to your crontab to run the command every minute.
4. Advanced usage
It may make sense to limit the runtime of an instance and restart the command regularly. Use the runtime option for this:
In order to run the command's execute() method more often in the main loop (default is 5 sec), you can use the frequency option to set a lower timeout between iterations (1 sec in this example):
Every iteration will refresh the lock and push its expiry time further into the future. If the command crashes, the lock will expire after the lock-ttl time and the next cronjob will start a new instance. You can set the lock-ttl to a lower value to ensure that the command is restarted more quickly after a crash:
TODO
- [ ] Examples
- [ ] Unit Tests