{"id":19562480,"url":"https://github.com/inpassor/yii2-daemon","last_synced_at":"2025-04-27T00:31:47.170Z","repository":{"id":56991874,"uuid":"69742054","full_name":"Inpassor/yii2-daemon","owner":"Inpassor","description":"The simple daemon extension for the Yii 2 framework","archived":false,"fork":false,"pushed_at":"2018-11-19T12:11:19.000Z","size":77,"stargazers_count":30,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T11:04:37.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inpassor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-01T14:05:59.000Z","updated_at":"2024-07-19T07:57:55.000Z","dependencies_parsed_at":"2022-08-21T13:50:19.384Z","dependency_job_id":null,"html_url":"https://github.com/Inpassor/yii2-daemon","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inpassor%2Fyii2-daemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inpassor%2Fyii2-daemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inpassor%2Fyii2-daemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inpassor%2Fyii2-daemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inpassor","download_url":"https://codeload.github.com/Inpassor/yii2-daemon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224050675,"owners_count":17247380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:14:44.306Z","updated_at":"2024-11-11T05:14:45.294Z","avatar_url":"https://github.com/Inpassor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The simple daemon extension for the Yii 2 framework\n\n[![Latest Stable Version](https://poser.pugx.org/inpassor/yii2-daemon/version)](https://packagist.org/packages/inpassor/yii2-daemon)\n[![Total Downloads](https://poser.pugx.org/inpassor/yii2-daemon/downloads)](https://packagist.org/packages/inpassor/yii2-daemon)\n[![License](https://poser.pugx.org/inpassor/yii2-daemon/license)](https://packagist.org/packages/inpassor/yii2-daemon)\n\nAuthor: Inpassor \u003cinpassor@yandex.com\u003e\n\nGitHub repository: https://github.com/Inpassor/yii2-daemon\n\nThis daemon is a console application of Yii2, implementing multitasking\nprocesses on PHP.\nWhen started, it stays in memory and launches workers.\nEvery worker process has an individual number of max processes running at once.\nInside the worker you can access any of Yii2 resources. \n\nNote that for the normal operation of the daemon you need the PHP extensions **pcntl**\nand **posix**.\nIf the daemon is running on a Windows system, forking is not available.\nAlso, the main process of the daemon remains in the console until it is interrupted (Ctrl-C).\n\n## Installation\n\n1) Add package to your project using composer:\n~~~\ncomposer require inpassor/yii2-daemon\n~~~\n\n2) Add the daemon command to the console config file in the \"controllerMap\" section:\n~~~\n'controllerMap' =\u003e [\n    ...\n    'daemon' =\u003e [\n        'class' =\u003e 'inpassor\\daemon\\Controller',\n        'uid' =\u003e 'daemon', // The daemon UID. Giving daemons different UIDs makes possible to run several daemons.\n        'pidDir' =\u003e '@runtime/daemon', // PID file directory.\n        'logsDir' =\u003e '@runtime/logs', // Log files directory.\n        'clearLogs' =\u003e false, // Clear log files on start.\n        'workersMap' =\u003e [\n            'watcher' =\u003e [\n                'class' =\u003e 'inpassor\\daemon\\workers\\Watcher',\n                'active' =\u003e true, // If set to false, worker is disabled.\n                'maxProcesses' =\u003e 1, // The number of maximum processes of the daemon worker running at once.\n                'delay' =\u003e 60, // The time, in seconds, the timer should delay in between executions of the daemon worker.\n            ],\n            ...\n        ],\n    ],\n],\n~~~\n\nA workers of the daemon sould be listed in the \"workersMap\" section. Parameter \"class\"\nis the only one that required. It is possible to set a worker config such way:\n~~~\n'workersMap' =\u003e [\n    'watcher' =\u003e 'inpassor\\daemon\\workers\\Watcher',\n    ...\n],\n~~~\nIn this case all the parameters will be taken from a worker class.\n\nNote that config variables of a worker defined in the \"workersMap\" config section\nof the daemon have priority over the corresponding properties of a worker class.\n\nThe daemon contains the worker \"inpassor\\daemon\\workers\\Watcher\".\nThis worker run once per minute and checks if workers of the daemon alive\nand removes a dead ones from the memory. It is not required.\n\n3) Create workers of the daemon. All the worker classes should extend\ninpassor\\daemon\\Worker :\n~~~\nclass MyWorker extends \\inpassor\\daemon\\Worker\n{\n    public $active = true;\n    public $maxProcesses = 1;\n    public $delay = 60;\n\n    public function run()\n    {\n        $this-\u003elog('I live... again!');\n        // The daemon worker's job goes here.\n    }\n\n}\n~~~\n\nThe public method run() of the worker should be overridden in the derivative class.\nDon't forget to add your workers to the \"workersMap\" section of the config of the daemon.\n\n## Run as system service for Ubuntu / Debian\n\n1) Make sure that in your project directory there is the console application \"yii\".\nCheck if the \"yii\" file is executable.\n\n2) Check if the \"vendor/inpassor/yii2-daemon/yiid\" file is executable.\n\n3) Run in root console:\n~~~\nln -s /path_to_your_project/vendor/inpassor/yii2-daemon/yiid /etc/init.d/yiid\n~~~\n\n4) Create the file /lib/systemd/system/yiid.service :\n~~~\n[Unit]\nDescription=yiid\n \n[Service]\nUser=www-data\nPIDFile=/path_to_your_project/runtime/daemon/daemon.pid\nType=forking\nKillMode=process\nExecStart=/path_to_your_project/vendor/inpassor/yii2-daemon/yiid start\nExecStop=/path_to_your_project/vendor/inpassor/yii2-daemon/yiid stop\n \n[Install]\nWantedBy=multi-user.target\n~~~\n\n5) Run in a root console:\n~~~\nsystemctl enable yiid.service\nservice yiid start\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finpassor%2Fyii2-daemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finpassor%2Fyii2-daemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finpassor%2Fyii2-daemon/lists"}