kcloze/swoole-jobs
Composer 安装命令:
composer require kcloze/swoole-jobs
包简介
基于swoole的job调度组件,类似gearman的分布式任务处理系统
关键字:
README 文档
README
中文介绍
- Distributed task processing system,similar to gearman,based on swoole
- High performance / dynamic multi woker process consumption queue to accelerate backend time consuming service
- There is no need to configure a crontab like gearman worker, swoole-jobs is responsible for managing all worker states
- Support for pushing queues by HTTP API(swoole http server) , does not depend on php-fpm
1. Explain
- Slower logic in web, such as statistical /email/ SMS / picture processing, etc.
- Support redis/rabbitmq/zeromq or any other queue message store.
- It is more stable and faster than the Yii / laravel framework itself.
- With yii2/phalcon/yaf/ThinkPHP5 integration example, other frameworks can refer to src/Action code.
- yii2 demo
- ThinkPHP5 demo
2. Architecture diagram
3. Characteristic
-
job scheduling component based on swoole; distributed task processing system similar to gearman;
-
redis/rabbitmq/zeromq and any other queue message store (currently only redis/rabbitmq).
-
use swoole process to realize multi process management, the number of processes can be configured, and the worker process will automatically pull up after exiting.
-
the number of cycles of child processes can be configured to prevent memory leakage from business code; the default stop command will wait for the child process to exit smoothly.
-
support topic features, different job binding different topic;
-
each topic starts the corresponding number of sub processes to eliminate the interaction between different topic.
-
according to the queue backlog, the sub process starts the process dynamically, and the number of the largest sub processes can be configured.
-
support composer, which can be integrated with any framework;
-
log file automatic cutting, default maximum 100M, up to 5 log files, prevent log brush full disk;
-
backlog, support for nail robot and other news alerts.
4. Install
4.1 composer
git clone https://github.com/kcloze/swoole-jobs.git
cd swoole-jobs
composer install
4.2 docker
- git clone https://github.com/kcloze/swoole-jobs.git
- cd swoole-jobs and composer install
- Building a mirror based on the root directory Dockerfile
- docker build -t swoole-jobs .
- docker run -it -v ~/data/code/php:/data swoole-jobs /bin/bash
- After entering the docker container, enter the project directory:
php ./bin/swoole-jobs.php start
5. How to running
5.1 example
1.edit config.php
2.start service
php ./bin/swoole-jobs.php start >> log/system.log 2>&1
3.push jobs
php ./tests/testJobsSerialzie.php
4.start api server
php ./bin/swoole-jobs.php http start
5.stop api server
php ./bin/swoole-jobs.php http stop
5.2 Start parameter description
NAME
- manage swoole-jobs
SYNOPSIS
-php bin/swoole-jobs.php app [options]
-Manage swoole-jobs daemons.
WORKFLOWS
-help [command]
-Show this help, or workflow help for command.
-restart
-Stop, then start swoole-jobs master and workers.
-start
-Start swoole-jobs master and workers.
-stop
-Wait all running workers smooth exit, please check swoole-jobs status for a while.
-exit
-Kill all running workers and master PIDs.
-http start
-Start swoole http server for apis.
-http stop
-Stop swoole http server for api.
5.3 API parameter description
5.3.1 api url
5.3.2 api params:
| Params | Type | Demo |
|---|---|---|
| jobData | json | {"topic":"MyJob","jobClass":"\Kcloze\Jobs\Jobs\MyJob","jobMethod":"test2","jobParams":["kcloze",1532857253,"oop"],"jobExtras":[],"serializeFunc":"php"} |
6. Service management
There are two ways to start and close the service online:
6.1 The startup script is added to the crontab timing task, which is executed once a minute (swoole-jobs automatically checks if it is executing, avoiding repeated startup).
* * * * * /usr/local/bin/php /***/swoole-jobs.php start >> /***/log/system.log 2>&1
6.2 Using SYSTEMd Management (failure restart, boot up)
1. According to your own project path, modify: docs/systemd/swoole-jobs.service
2. sudo cp -f systemd/swoole-jobs.service /etc/systemd/system/
3. sudo systemctl --system daemon-reload
4. Service management
#start service sudo systemctl start swoole-jobs.service #reload service sudo systemctl reload swoole-jobs.service #stop service sudo systemctl stop swoole-jobs.service
7.System screenshot
htop
status
dingding message
8. Change log
9. Matters needing attention
- If you embed your own framework, you can refer to src/Action code to inherit the abstract class Kcloze\Jobs\Action\BaseAction.
- Various framework services will start slightly different, for specific reference: Code for
example/binprojects. - swoole >=4 version,need to set php.ini, disable coroutine
10. Pressure measurement
- Bottleneck: redis/rabbitmq queue storage itself and job execution speed
11. Thanks
12. Contact
qq group:141059677
13. Donation
- If this project really helps you, please click on the top right corner for a star.
kcloze/swoole-jobs 适用场景与选型建议
kcloze/swoole-jobs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.14k 次下载、GitHub Stars 达 579, 最近一次更新时间为 2016 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「job」 「scheduler」 「swoole」 「调度」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kcloze/swoole-jobs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kcloze/swoole-jobs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kcloze/swoole-jobs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
Provides a possibility to auto-setup crontabs required for project based on configuration file.
SlimQ Enables You to push jobs to background workers
PHP client for Kue priority job queue API
Swoole server process management
Reset scheduler tasks
统计信息
- 总下载量: 3.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 579
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-31




