nexxes /daemonhelper
用PHP编写的守护进程辅助类
dev-master
2018-02-05 09:28 UTC
Requires (Dev)
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-09-14 17:53:34 UTC
README
用PHP编写的守护进程辅助类,许可协议为LGPL v3。
安装
只需将以下内容放入您项目根目录下的 composer.json
文件中。目前尚无稳定版本。
"require": { "nexxes/daemonhelper": "*@dev" }
特性
将进程守护化
// Daemonize the current process: // - process will be detached from terminal and becomes process group leader // - stdin/stderr will be closed and reopened to the supplied files (default is /dev/null) // - daemon will re-exec itself so STDIN, STDOUT, STDERR constants are fixed \nexxes\Daemon::daemonize('run/process.pid', 'log/stderr.log', 'log/stdout.log', 'stdin.txt'); // Code after daemonizing follows here // ...
在出错时重启工作进程的WatchDog
// Fork the real worker process \nexxes\WatchDog::run(); // Code for the worker process // If the process dies with exit-value != 0, // we start here again and again and again // ..
支持多个工作进程的WatchDog
// Multiple processes can be handled by a watchdog instance $watchdog = new \nexxes\WatchDog(); $watchdog->addProcess('processName1', function() { // Code for process 1 // If the process dies with exit-value != 0, // we start here again ... }); $watchdog->addProcess('processNameX', function() { // Register as many processes as you need. // You can register anything callable, not only closures. }); // Execute the processes and restart them if needed: $watchdog->start();