depaco/codeigniter-swoole
Composer 安装命令:
composer require depaco/codeigniter-swoole
包简介
A swoole adapter for Codeigniter 3.0+
README 文档
README
You want long-run task? timers? FPM to CLI? Code reusing in both FPM & CLI mode?
"It's so easy!"
This adapter would make it so easy to using swoole within Codeigniter framework.
With this adapter, you can start a task(CLI) any where(FPM) you want from your code.
That's means you can start a CLI task from a FPM process.
Install
composer require lanlin/codeigniter-swoole
How to
- first, of course you must install
codeigniter-swooleto your codeigniter project. - (this step is option) copy these two config files
swoole.phpandtimers.phpfromsrc/Helperto yourapplication/configfolder. - start swoole server
php index.php swoole/server/start - you can use
\CiSwoole\Core\Client::send($data)to start a task now! - there's no step 5.
What is a task?
A task is just a method of your codeigniter controlloer, so almost any controller method can be used as a task.
Let's see the code
\CiSwoole\Core\Client::send( [ 'route' => 'your/route/uri/to/a/method' 'params' => ['test' => 666] ], $fd, $callback);
The route is used for find which method to be call as a task, and params is the parameters array that you may want to pass to the task.
fd and callback params are used to notify about task errors.
So, that's all of it!
Server CLI Commands
// start the swoole server php index.php swoole/server/start // stop the swoole server php index.php swoole/server/stop // reload all wokers of swoole server php index.php swoole/server/reload
A little more
The step 2 copied files were config files for this adapter.
swoole.php file can set host, port, log file and so on.
timers.php file can set some timer methods for swoole server, these timers will be started once the server inited.
You can copy tests/application to your application for testing. The demos are same as below shows.
class Test extends CI_Controller { // ------------------------------------------------------------------------------ /** * here's the task 'tests/test/task' */ public function task() { $data = $this->input->post(); // as you see, params worked like normally post data log_message('info', var_export($data, true)); } // ------------------------------------------------------------------------------ /** * here's the timer method * * you should copay timers.php to your config folder, * then add $timers['tests/test/task_timer'] = 10000; and start the swoole server. * * this method would be called every 10 seconds per time. */ public function task_timer() { log_message('info', 'timer works!'); } // ------------------------------------------------------------------------------ /** * send data to task */ public function send() { try { \CiSwoole\Core\Client::send( [ 'route' => 'tests/test/task', 'params' => ['hope' => 'it works!'], ]); } catch (\Exception $e) { log_message('error', $e->getMessage()); log_message('error', $e->getTraceAsString()); } } // ------------------------------------------------------------------------------ }
License
This project is licensed under the MIT license.
depaco/codeigniter-swoole 适用场景与选型建议
depaco/codeigniter-swoole 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「codeigniter」 「adapter」 「task」 「timers」 「swoole」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 depaco/codeigniter-swoole 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 depaco/codeigniter-swoole 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 depaco/codeigniter-swoole 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adapter designed to add Framework Agnosticism for Caching within PHP Packages.
flysystem cache Adapter
Virtual Filesystem Storage Adapter for Laravel
The CodeIgniter Redis package
A simple interface for composite Flysystem adapters
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-19