Download the PHP package citysites/yii2-daemon without Composer
On this page you can find all versions of the php package citysites/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. There is also a daemons supervisor.
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 WatcherDaemon (Supervisor)
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 your console controllers path file for ex. DaemonsSupervisorController.php with following content:
or get this jobs array from file, for example json array
And file.json
format:
or get running daemon list from database
- 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 your 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.$isJobsListPersistent
- change jobs list processing method. If false job list processing always while have job and free worker. If true - jobs list processing from first job to last and sleep workers for sleep time after which worker starts again with the processing of the first job.Daemon control
Daemon catch a some signal and do some action. Below are the list of catch signals and the actions of the daemon when they are received:
- SIGINT, SIGTERM - daemon shutdown, break from loop write log data and closure used resources.
- SIGCHLD - shutdown all child workers, main daemon process still work.
- SIGUSR1 - write to linux syslog information about daemon uptime.
Logger settings
If you want to change logging preferences, you may override the function initLogger. Example:
Installing Proctitle on PHP < 5.5.0
You will need proctitle extension on your server to be able to isntall yii2-daemon. For a debian 7 you can use these commands: