Download the PHP package jet-snowman/yii2-daemon without Composer
On this page you can find all versions of the php package jet-snowman/yii2-daemon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jet-snowman/yii2-daemon
More information about jet-snowman/yii2-daemon
Files in jet-snowman/yii2-daemon
Package yii2-daemon
Short Description Extension provides functionality for simple daemons creation and control
License BSD-3-Clause
Informations about the package yii2-daemon
Daemons
A base daemon has 3 methods:
- initModule()
- runModule()
- stopModule()
It's located in package jet-snowman\daemon\BaseDaemonController.
For each method you can add your logic. For example inside initModule can be initialization of some connection and in the method stopModule can be closing connection. The method runModule() executes in a loop. For development the method runs once and you don't need to stop a daemon every time. When one iteration is done a daemon updates pid file that allows to track a status of the daemon. A task inside runModule() must be light, for example if an iteration takes 1 minute it means to stop a daemon takes at least 1 minute and in case an exception you will lose your progress so a task must be small and should take less than 5 seconds to finish it.
If pid file wasn't updated for X time the Watcher will kill and start the daemon again. The watcher is always running, it monitors all daemons in the server so before to stop your daemon you have to make sure you stopped the Watcher first.
The configuration of watcher can be found here - /console/controllers/WatcherDaemonController.php
daemon - it's the name of daemon that can be found when you run ./yii
enabled - you can enable or disable some daemon
debug - if it's enabled then daemon will be ran with debug flag
kill - if it's enabled then the watcher will kill a daemon after X time
maxTime - the max time between iterations
Daemon Bin folder
The patch is ./bin. To create a runnable file you can copy some existed daemon and you need to define the following constants:
DAEMON_NAME - can be any name
DAEMON_BIN_NAME - must be taken from ./yii and the same name must be used in the watcher configuration
DAEMON_PID_NAME - can be any name but without slashes
Rabbit Base Daemon
The base class is located - jet-snowman\daemon\controllers\RabbitMQBaseDaemonController and you have the following methods
- initModule() - you have to set your queue name.
- stopModule()
- getChannel() - you have to return a channel
- handleMessage($message) - yo have to handle your task
The message is an instance of \PhpAmqpLib\Message\AMQPMessage. The handleMessage calls every time when rabbit sends a task to a worker. Only one task can be handled in one iteration.
Sqs Base Daemon
The base class is located - jet-snowman\daemon\controllers\SqsBaseDaemonController and you have the following methods
- initModule() - you have to set your queue name.
- handleMessage($message) - yo have to handle your task
The message is an instance of Array. The handleMessage calls every time when a worker gets a new response. If response has more than 1 message then it will be called multiple times for one iteration.
All versions of yii2-daemon with dependencies
ext-pcntl Version *
ext-posix Version *
jet-snowman/yii2-consolelog Version dev-master