multiprocess
- [readme in english]
- 基于swoole的脚本管�?�,用于多进程和守护进程管�?�;
- �?�轻�?�让普通脚本�?�守护进程和多进程执行;
- 进程个数�?��?置,�?ï¿½ä»¥æ ¹ï¿½?��?置一次性执行多�?�命令;
- �?进程异常退出时,主进程收到信�?�,自动拉起�?新执行;
- 支�?�?进程平滑退出,防æ¢ï¿½?�?��?åŠ¡å¯¹ä¸šåŠ¡é€ ï¿½?影�?ï¼›
- �?�?定编程è¯è¨€ï¼ŒPHP/Python/Java/Golang/C#ç‰è„šæœ¬éƒ½ï¿½?�以管�?�
1. 场景
- PHP/python/jsç‰è„šæœ¬éœ€ï¿½?跑一个或多个脚本消费队列/计算ç‰ä»»åŠ¡
- 实现脚本退出�?ï¿½è‡ªåŠ¨æ‹‰èµ·ï¼Œé˜²æ¢æ¶ˆè´¹é˜Ÿåˆ—�?工作,影�?业务
- 其实supervisor�?�以轻�?��?�个事情,这个�?�是PHP的�?�一�?实现,�?需�?�?ï¿½æŠ€æœ¯æ ˆ
2. �?程图
3. 安装
- git clone https://github.com/kcloze/multiprocess.git
- composer install
- æ ¹ï¿½?�自己业务�?ç½®,修改config.php
4. �?置实例
- 一次性执行多个命令
'logPath' => __DIR__ . '/log',
'exec' => [
[
'name' => 'kcloze-test-1',
'bin' => '/usr/bin/php',
'binArgs' => [__DIR__ . '/test/test.php', 'oop', '123'],
'workNum' => 3,
],
[
'name' => 'kcloze-test-2',
'bin' => '/usr/bin/php',
'binArgs' => [__DIR__ . '/test/test2.php', 'oop', '456'],
'workNum' => 5,
],
[
'name' => 'kcloze-test-3',
'bin' => '/usr/bin/python',
'binArgs' => [__DIR__ . '/test/test3.py', 'oop', '369'],
'workNum' => 2,
],
],
5. �?行
5.1 �?�动
- chmod -R u+r log/
- php multiprocess.php start >> log/system.log 2>&1
5.2 平滑�?�æ¢ï¿½?åŠ¡ï¼Œæ ¹ï¿½?��?进程执行时间ç‰å¾…所有�?务�?�æ¢
- php multiprocess.php stop
5.3 强制�?�æ¢ï¿½?务[慎用]
- php multiprocess.php exit
5.4 强制�?�?�
- php multiprocess.php restart >> log/system.log 2>&1
5.5 监控
- ps -ef|grep 'multi-process'
5.6 �?�动�?�数说明
NAME
php multiprocess - manage multiprocess
SYNOPSIS
php multiprocess -s command [options] -c config file path
Manage multiprocess daemons.
WORKFLOWS
help [command]
Show this help, or workflow help for command.
-s restart
Stop, then start multiprocess master and workers.
-s start
Start multiprocess master and workers.
-s start -c ./config
Start multiprocess with specail config file.
-s stop
Wait all running workers smooth exit, please check multiprocess status for a while.
-s exit
Kill all running workers and master PIDs.
6. �?务管�?�
�?�动和关é—�?务,有两�?方�?:
6.1 php脚本(主进程挂了之�?�,需�?手动�?�动)
./multiprocess.php start|stop|exit|restart
6.2 使用systemd管�?�(故障�?�?��?开机自�?�动)
1. æ ¹ï¿½?�自己项目路径,修改 systemd/multiprocess.service
2. sudo cp -f systemd/multiprocess.service /etc/systemd/system/
3. sudo systemctl --system daemon-reload
4. �?务管�?�
#�?�动�?务
sudo systemctl start multiprocess.service
#reload�?务
sudo systemctl reload multiprocess.service
#å…³é—�?务
sudo systemctl stop multiprocess.service
7. 系统状�?
8. change log
2017-11-30
- 彻底�?构v2版本
- å¢žåŠ exit�?�动�?�数,默认stopç‰å¾…�?进程平滑退出
9. 感谢
10. �?�系
qq群:141059677

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.


