• Stars
    star
    184
  • Rank 202,546 (Top 5 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Workerman extend for ThinkPHP

ThinkPHP 6.0 Workerman 扩展

安装

composer require topthink/think-worker

使用方法

HttpServer

在命令行启动服务端

php think worker

然后就可以通过浏览器直接访问当前应用

http://localhost:2346

linux下面可以支持下面指令

php think worker [start|stop|reload|restart|status]

workerman的参数可以在应用配置目录下的worker.php里面配置。

由于onWorkerStart运行的时候没有HTTP_HOST,因此最好在应用配置文件中设置app_host

SocketServer

在命令行启动服务端

php think worker:server

默认会在0.0.0.0:2345开启一个websocket服务。

如果需要自定义参数,可以在config/worker_server.php中进行配置,包括:

配置参数 描述
protocol 协议
host 监听地址
port 监听端口
socket 完整的socket地址

并且支持workerman所有的参数。 也支持使用闭包方式定义相关事件回调。

return [
	'socket' 	=>	'http://127.0.0.1:8000',
	'name'		=>	'thinkphp',
	'count'		=>	4,
	'onMessage'	=>	function($connection, $data) {
		$connection->send(json_encode($data));
	},
];

也支持使用自定义类作为Worker服务入口文件类。例如,我们可以创建一个服务类(必须要继承 think\worker\Server),然后设置属性和添加回调方法

<?php
namespace app\http;

use think\worker\Server;

class Worker extends Server
{
	protected $socket = 'http://0.0.0.0:2346';

	public function onMessage($connection,$data)
	{
		$connection->send(json_encode($data));
	}
}

支持workerman所有的回调方法定义(回调方法必须是public类型)

然后在worker_server.php中增加配置参数:

return [
	'worker_class'	=>	'app\http\Worker',
];

定义该参数后,其它配置参数均不再有效。

在命令行启动服务端

php think worker:server

然后在浏览器里面访问

http://localhost:2346

如果在Linux下面,同样支持reload|restart|stop|status 操作

php think worker:server reload

More Repositories

1

think

ThinkPHP Framework ——十年匠心的高性能PHP框架
PHP
7,795
star
2

thinkphp

ThinkPHP3.2 ——基于PHP5的简单快速的面向对象的PHP框架
PHP
2,879
star
3

framework

ThinkPHP Framework
PHP
2,671
star
4

think-queue

ThinkPHP 队列支持
PHP
555
star
5

think-swoole

Swoole extend for thinkphp
PHP
444
star
6

think-orm

Think ORM——the PHP Database&ORM Framework
PHP
385
star
7

think-awesome

awesome for thinkphp
242
star
8

think-throttle

thinkphp 限制访问频率的中间件
PHP
176
star
9

think-captcha

thinkphp 验证码类库
PHP
112
star
10

think-mongo

mongodb driver for thinkphp
PHP
101
star
11

think-migration

thinkphp 数据库迁移工具
PHP
89
star
12

think-helper

thinkphp常用的助手类 助手函数
PHP
78
star
13

thinkphp-extend

PHP
73
star
14

think-image

thinkphp5 图像处理类
PHP
59
star
15

think-validate

think Validate
PHP
51
star
16

think-template

the php template engine
PHP
49
star
17

think-annotation

ThinkPHP6注解
PHP
43
star
18

think-angular

think-angular模板引擎
PHP
40
star
19

think-testing

ThinkPHP 5 应用单元测试组件
PHP
40
star
20

think-oracle

Oracle数据库驱动
PHP
36
star
21

think-cache

PHP Cache Service
PHP
31
star
22

think-ide-helper

PHP
24
star
23

think-api

官方API服务SDK
PHP
22
star
24

think-multi-app

thinkphp6 multi app support
PHP
21
star
25

think-debugbar

ThinkPHP Debugbar (Integrates PHP Debug Bar)
PHP
17
star
26

think-glide

ThinkPHP adapter for using Glide image manipulation library
PHP
16
star
27

think-seaslog

SeasLog driver for thinkphp
PHP
15
star
28

think-editor

The ThinkPHP5 Editor Package
PHP
15
star
29

think-view

thinkphp driver for think-template
PHP
14
star
30

think-installer

PHP
14
star
31

think-container

PHP Container & Facade Manager
PHP
14
star
32

thinkng-webapp

Thinkng的应用模板
PHP
12
star
33

think-sae

sae support for thinkphp5
PHP
11
star
34

think-workflow

ThinkPHP6状态机
PHP
11
star
35

think-log

PHP
10
star
36

think-trace

debug trace bar for thinkphp6
PHP
9
star
37

think-filesystem

thinkphp 文件系统
PHP
8
star
38

think-tracing

PHP
8
star
39

think-one

一个tp5的辅助开发插件
HTML
7
star
40

think-csrf

thinkphp5 CSRF 保护组件
5
star
41

think-yaconf

PHP
4
star
42

think-socketlog

socketlog driver for thinkphp
PHP
4
star
43

cache-bridge

PSR-16 to PSR-6 Bridge
PHP
3
star
44

think-factory

thinkphp 工厂类
PHP
2
star