Download the PHP package consik/yii2-daemons without Composer

On this page you can find all versions of the php package consik/yii2-daemons. 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-daemons

Yii2 daemons by systemd

Latest Stable Version Total Downloads License

Introduction

There is no concrete realization for daemonizing PHP scripts by using pcntl_fork() or something else. We don't need it, when we have package like systemd that can make service from our PHP script. So, there is DaemonInterface in package that has only two methods startDaemon() and stopDaemon(), and one AbstractLoopDaemon that implements this interface.

You can use your own script, that working in background, just implement there DaemonInterface.

All functions that makes daemon from your PHP script will do systemd and ServiceController.

Installation

The preferred way to install this extension is through composer.

Either run

or add

Creating daemon.

As I say above all that you need is to implement DaemonInterface.

Simple looped daemon:

In this realizaton stopDaemon() never called and we lost result when daemon will be terminated;

Now let's make same daemon by extending AbstractLoopDaemon with extensions from this package as ServiceConfigInterface and LoopDaemonSignalsBehavior.

This daemon increment $i each 10 seconds by 1. Also there used LoopDaemonSignalsBehavior and we handle SIGTERM signal, that dispatch 'stopDaemon' method. When this daemon stopped it will output current value of $i.

For more information about handling signals see docs about pcntl_signal() For easy realization you can use HandleSignalsBehavior or LoopDaemonSignalsBehavior if you extends AbstractLoopDaemon. If you will use HandleSignalsBehavior don't forget calling or pcntl_signal_dispatch().

ServiceConfigInterface has one method getServiceConfig(). This method will be used by ServiceController for getting current daemon systemd unit params.

Using ServiceController

Use ServiceController in your app for easy making systemd units and controlling your daemons.

config\console.php:

Generating systemd units.

For generating systemd unit files use this command:

Registering service.

ServiceController can only generate systemd unit(*.service) file by action systemd-file There is a bash script in package for fast registering systemd units in system. Using example, after service controller is configured:

Controlling your daemon:

Checking your daemon status:

Starting service:

Restarting service

Stopping service:

also you can use ServiceController methods like status and stop, but better use systemctl functions:

Checking status by ServiceController:

Stopping daemon by sending SIGTERM signal for daemon process:

@see for more information about unit files configuration and controlling your daemons.

Configuring systemd units

There are three sources with params that used for generating systemd unit. Array structure for all sources below is:

It equals service unit file:

See available options in official docs

All of configuration sources below sorted by priority:

Concrete daemon service configuration. Override common services configuration.

It will be used if the daemon implements ServiceConfigInterface. ServiceController calls method for getting configuration. Example setting systemd unit params for each daemon

Implement ServiceConfigInterface in your daemon and declare function

Defining your daemon config params:

Common services configuration. Override basic service configuration. Var ServiceController::$commonServiceConfig.

It can be changed in your controller configuration. Yii2 console config file:

Basic service configuration. Lowest priority params. Returns by method .

This method returns basic systemd unit configuration for all daemons(Service: ExecStart, Type; Unit: Description, After; Install: WantedBy). As default all generated services starts after mysql.service. Override param After in section Unit if you don't need it or if your daemon have other dependencies(mongodb.service for example).

All of these configurations will be merged by array_replace_recursive() before generating each daemon config file;


All versions of yii2-daemons 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 consik/yii2-daemons contains the following files

Loading the files please wait ....