Download the PHP package kfosoft/yii2-daemon without Composer
On this page you can find all versions of the php package kfosoft/yii2-daemon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-daemon
Daemons system for Yii2
Extension provides functionality for simple daemons creation and control
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Setting SingleJob
- Create command class and implement the SingleJobInterface.
- Implement logic in
__invoke
method and please return time for sleep fromsleepTime
method.
Setting WatcherDaemon
WatcherDaemon is the main daemon and provides from box. This daemon check another daemons and run, if it need. Do the following steps:
-
Create in you console controllers path file WatcherDaemonController.php with following content:
- No one checks the Watcher. Watcher should run continuously. Add it to your crontab:
Watcher can't start twice, only one instance can work in the one moment.
Usage
Create new daemons
-
Create in you console controllers path file {NAME}DaemonController.php with following content:
- Implement logic.
- Add new daemon to daemons list in watcher.
Working with RabbitMQ (this example needs "videlalvaro/php-amqplib" package)
Daemon settings (propeties)
In your daemon you can override parent properties:
$demonize
- if 0 daemon is not running as daemon, only as simple console application. It's needs for debug.$memoryLimit
- if daemon reach this limit - daemon stop work. It prevent memory leaks. After stopping WatcherDaemon run this daemon again.$sleep
- delay between checking for new task, daemon will not sleep if task list is full.$pidDir
- dir where daemons pids is located$logDir
- dir where daemons logs is located$isMultiInstance
- this option allow daemon create self copy for each task. That is, the daemon can simultaneously perform multiple tasks. This is useful when one task requires some time and server resources allows perform many such task.$maxChildProcesses
- only if$isMultiInstance=true
. The maximum number of daemons instances. If the maximum number is reached - the system waits until at least one child process to terminate.
If you want to change logging preferences, you may override the function initLogger. Example:
All versions of yii2-daemon with dependencies
yiisoft/yii2 Version >=2.0.34
ext-pcntl Version *
ext-json Version *
ext-posix Version *