# thinkphp-workerman-httpServer **Repository Path**: zwk520/thinkphp-workerman-http-server ## Basic Information - **Project Name**: thinkphp-workerman-httpServer - **Description**: thinkphp-workerman-httpServer - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4 - **Created**: 2023-10-31 - **Last Updated**: 2023-10-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # thinkphp-workerman #### 介绍 针对thinkphp8 还未及时更新workerman版本,内置版本还是workerman3,所以我适配了最新版本 **无需改动tp框架代码,不会对原有目录任何改动** 只需使用composer安装最新版workerman,将command放入你项目的app目录下 **使用webman加载方式,支持全部协议;** **支持webman方式进行自定义进程(配置上略有改动)** **已内置QUEUE/TIMING/HTTP** #### 使用 config/console.php -> commands加入 'workerman' => Start::class 在workerman目录下process.php文件中进行进程配置,handler引入进程类 命令行: php think workerman ===================== 【timing】 ===================== #### 任务设置 timing/Handler中 #### 使用方法 ``` run(类路径,执行发放名(默认job)) 间隔2秒: (new Client)->setInterval(2)->run(Test::class); 周3、12点: (new Client)->setFixTimeWeek(3)->setFixTimeHour(12)->run(Test::class); 间隔5秒、但在第5秒15秒20秒不执行: (new Client)->setInterval(5)->setExcludeSecond([5, 15, 20])->run(Test::class); 更多使用方法,timing/Client类中查看 ``` #### 注意 ``` ->run(类路径,执行方法名默认job) ->setBefore() // 在固定时间执行运行时候,是否执行一次 周、月、日 没有前导“0”; 时、分、秒 必须有前导“0” 否则会导致不准确 ``` ===================== 【queue】 ===================== #### 任务订阅: queue/Handler中 #### 任务发布: ``` app(Client:class)->send( $queue = '', // 队列名 $data = [], // 任务数据 $delay = 0, // 延迟队列时长,单位:秒 $maxRetry = null, // 最大重试次数(默认3次) $retryInterval = null // 每次重试间隔秒数(默认5秒) ); ``` #### 注意 Client::class 中队列$id自行改为自己的方法即可,这里我没有上传雪花算法 ===================== 【http】 ===================== #### 注意 file_get_contents('php://input') 不可用,解决方法:request()->getInput() nginx代理: ``` upstream webman { server 127.0.0.1:8787; keepalive 10240; } server { server_name 站点域名; listen 80; access_log off; root /your/webman/public; location ^~ / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; 【这个地方不要复制webman的$host,否则request()->host()无法获取不到nginx的自定义端口】 proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Connection ""; if (!-f $request_filename){ proxy_pass http://webman; } } } ``` #### 未解决问题 因中间件配置会在内存中保留,所以在多应用中存在跨应用的问题 (其实可以不使用官方的多应用库,通过自己监听httpinit事件写多应用识别来解决此事)