Download the PHP package inpassor/yii2-daemon without Composer

On this page you can find all versions of the php package inpassor/yii2-daemon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-daemon

The simple daemon extension for the Yii 2 framework

Latest Stable Version Total Downloads License

Author: Inpassor [email protected]

GitHub repository: https://github.com/Inpassor/yii2-daemon

This daemon is a console application of Yii2, implementing multitasking processes on PHP. When started, it stays in memory and launches workers. Every worker process has an individual number of max processes running at once. Inside the worker you can access any of Yii2 resources.

Note that for the normal operation of the daemon you need the PHP extensions pcntl and posix. If the daemon is running on a Windows system, forking is not available. Also, the main process of the daemon remains in the console until it is interrupted (Ctrl-C).

Installation

1) Add package to your project using composer:

composer require inpassor/yii2-daemon

2) Add the daemon command to the console config file in the "controllerMap" section:

'controllerMap' => [
    ...
    'daemon' => [
        'class' => 'inpassor\daemon\Controller',
        'uid' => 'daemon', // The daemon UID. Giving daemons different UIDs makes possible to run several daemons.
        'pidDir' => '@runtime/daemon', // PID file directory.
        'logsDir' => '@runtime/logs', // Log files directory.
        'clearLogs' => false, // Clear log files on start.
        'workersMap' => [
            'watcher' => [
                'class' => 'inpassor\daemon\workers\Watcher',
                'active' => true, // If set to false, worker is disabled.
                'maxProcesses' => 1, // The number of maximum processes of the daemon worker running at once.
                'delay' => 60, // The time, in seconds, the timer should delay in between executions of the daemon worker.
            ],
            ...
        ],
    ],
],

A workers of the daemon sould be listed in the "workersMap" section. Parameter "class" is the only one that required. It is possible to set a worker config such way:

'workersMap' => [
    'watcher' => 'inpassor\daemon\workers\Watcher',
    ...
],

In this case all the parameters will be taken from a worker class.

Note that config variables of a worker defined in the "workersMap" config section of the daemon have priority over the corresponding properties of a worker class.

The daemon contains the worker "inpassor\daemon\workers\Watcher". This worker run once per minute and checks if workers of the daemon alive and removes a dead ones from the memory. It is not required.

3) Create workers of the daemon. All the worker classes should extend inpassor\daemon\Worker :

class MyWorker extends \inpassor\daemon\Worker
{
    public $active = true;
    public $maxProcesses = 1;
    public $delay = 60;

    public function run()
    {
        $this->log('I live... again!');
        // The daemon worker's job goes here.
    }

}

The public method run() of the worker should be overridden in the derivative class. Don't forget to add your workers to the "workersMap" section of the config of the daemon.

Run as system service for Ubuntu / Debian

1) Make sure that in your project directory there is the console application "yii". Check if the "yii" file is executable.

2) Check if the "vendor/inpassor/yii2-daemon/yiid" file is executable.

3) Run in root console:

ln -s /path_to_your_project/vendor/inpassor/yii2-daemon/yiid /etc/init.d/yiid

4) Create the file /lib/systemd/system/yiid.service :

[Unit]
Description=yiid

[Service]
User=www-data
PIDFile=/path_to_your_project/runtime/daemon/daemon.pid
Type=forking
KillMode=process
ExecStart=/path_to_your_project/vendor/inpassor/yii2-daemon/yiid start
ExecStop=/path_to_your_project/vendor/inpassor/yii2-daemon/yiid stop

[Install]
WantedBy=multi-user.target

5) Run in a root console:

systemctl enable yiid.service
service yiid start

All versions of yii2-daemon with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inpassor/yii2-daemon contains the following files

Loading the files please wait ....