diff --git a/App/Task/BroadcastTask.php b/App/Task/BroadcastTask.php index 2380f93..90a1618 100644 --- a/App/Task/BroadcastTask.php +++ b/App/Task/BroadcastTask.php @@ -22,6 +22,7 @@ */ class BroadcastTask extends AbstractAsyncTask { + /** * 执行投递 * @param $taskData @@ -29,8 +30,9 @@ class BroadcastTask extends AbstractAsyncTask * @param $fromWorkerId * @return bool */ - function run($taskData, $taskId, $fromWorkerId,$flags = null) + protected function run($taskData, $taskId, $fromWorkerId, $flags = null) { + // TODO: Implement run() method. $redis = Redis::getInstance()->getConnect(); $users = $redis->hGetAll(AppConst::REDIS_ONLINE_KEY); /** @var \swoole_websocket_server $server */ diff --git a/README.md b/README.md index b2861a8..7dc3036 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,61 @@ cp sample.env dev.env ## 配置 -修改 `dev.env` 内的配置项 +修改 `dev.php` 内的配置项 ```ini -SYSTEM.WS_SERVER_PATH = # 你的ws服务地址 如 : ws://127.0.0.1:9501 -REDIS.HOST = 127.0.0.1 # redis服务器地址 -REDIS.PORT = 6379 # redis服务器端口 -REDIS.AUTH = # redis服务器密码 (如果没有密码请注释本行) + "EasySwoole", + 'MAIN_SERVER' => [ + 'LISTEN_ADDRESS' => '0.0.0.0', + 'PORT' => 9501, + 'SERVER_TYPE' => EASYSWOOLE_WEB_SOCKET_SERVER, //可选为 EASYSWOOLE_SERVER EASYSWOOLE_WEB_SERVER EASYSWOOLE_WEB_SOCKET_SERVER + 'SOCK_TYPE' => SWOOLE_TCP, + 'RUN_MODEL' => SWOOLE_PROCESS, + 'SETTING' => [ + 'worker_num' => 8, + 'max_request' => 5000, + 'task_worker_num' => 8, + 'task_max_request' => 1000, + 'document_root' => EASYSWOOLE_ROOT.'/Static', + 'enable_static_handler' => true, + 'heartbeat_idle_time' => 600, # 10分钟无操作则掉线 + 'heartbeat_check_interval' => 60 # 每隔一分钟检查一次 + ], + ], + 'TEMP_DIR' => null, + 'LOG_DIR' => null, + 'CONSOLE' => [ + 'ENABLE' => true, + 'LISTEN_ADDRESS' => '127.0.0.1', + 'HOST' => '127.0.0.1', + 'PORT' => 9500, + 'EXPIRE' => '120', + 'AUTH' => null, + 'PUSH_LOG' => true, + ], + 'FAST_CACHE' => [ + 'PROCESS_NUM' => 0, + 'BACKLOG' => 256, + ], + 'DISPLAY_ERROR' => true, + 'SYSTEM' => [ + 'WS_SERVER_PATH' => 'ws://127.0.0.1:9501', # 你的ws服务地址 如 : ws://127.0.0.1:9501 + 'LAST_MESSAGE_MAX' => 10 + ], + 'REDIS' => [ + 'HOST' => '127.0.0.1', # redis服务器地址 + 'PORT' => 6379 # redis服务器端口 + ] +]; ``` ## 启动 diff --git a/dev.php b/dev.php new file mode 100644 index 0000000..4261c14 --- /dev/null +++ b/dev.php @@ -0,0 +1,52 @@ + "EasySwoole", + 'MAIN_SERVER' => [ + 'LISTEN_ADDRESS' => '0.0.0.0', + 'PORT' => 9501, + 'SERVER_TYPE' => EASYSWOOLE_WEB_SOCKET_SERVER, //可选为 EASYSWOOLE_SERVER EASYSWOOLE_WEB_SERVER EASYSWOOLE_WEB_SOCKET_SERVER + 'SOCK_TYPE' => SWOOLE_TCP, + 'RUN_MODEL' => SWOOLE_PROCESS, + 'SETTING' => [ + 'worker_num' => 8, + 'max_request' => 5000, + 'task_worker_num' => 8, + 'task_max_request' => 1000, + 'document_root' => EASYSWOOLE_ROOT.'/Static', + 'enable_static_handler' => true, + 'heartbeat_idle_time' => 600, # 10分钟无操作则掉线 + 'heartbeat_check_interval' => 60 # 每隔一分钟检查一次 + ], + ], + 'TEMP_DIR' => null, + 'LOG_DIR' => null, + 'CONSOLE' => [ + 'ENABLE' => true, + 'LISTEN_ADDRESS' => '127.0.0.1', + 'HOST' => '127.0.0.1', + 'PORT' => 9500, + 'EXPIRE' => '120', + 'AUTH' => null, + 'PUSH_LOG' => true, + ], + 'FAST_CACHE' => [ + 'PROCESS_NUM' => 0, + 'BACKLOG' => 256, + ], + 'DISPLAY_ERROR' => true, + 'SYSTEM' => [ + 'WS_SERVER_PATH' => 'ws://127.0.0.1:9501', + 'LAST_MESSAGE_MAX' => 10 + ], + 'REDIS' => [ + 'HOST' => '127.0.0.1', + 'PORT' => 6379 + ] +]; diff --git a/produce.php b/produce.php new file mode 100644 index 0000000..443c7a8 --- /dev/null +++ b/produce.php @@ -0,0 +1,40 @@ + "EasySwoole", + 'MAIN_SERVER' => [ + 'LISTEN_ADDRESS' => '0.0.0.0', + 'PORT' => 9501, + 'SERVER_TYPE' => EASYSWOOLE_WEB_SERVER, //可选为 EASYSWOOLE_SERVER EASYSWOOLE_WEB_SERVER EASYSWOOLE_WEB_SOCKET_SERVER + 'SOCK_TYPE' => SWOOLE_TCP, + 'RUN_MODEL' => SWOOLE_PROCESS, + 'SETTING' => [ + 'worker_num' => 8, + 'max_request' => 5000, + 'task_worker_num' => 8, + 'task_max_request' => 1000, + ], + ], + 'TEMP_DIR' => null, + 'LOG_DIR' => null, + 'CONSOLE' => [ + 'ENABLE' => true, + 'LISTEN_ADDRESS' => '127.0.0.1', + 'HOST' => '127.0.0.1', + 'PORT' => 9500, + 'EXPIRE' => '120', + 'AUTH' => null, + 'PUSH_LOG' => true, + ], + 'FAST_CACHE' => [ + 'PROCESS_NUM' => 0, + 'BACKLOG' => 256, + ], + 'DISPLAY_ERROR' => true, +]; diff --git a/sample.env b/sample.env deleted file mode 100644 index a641ccf..0000000 --- a/sample.env +++ /dev/null @@ -1,46 +0,0 @@ -# eg: -# mysql.port = 3306 -# MAIN_SERVER.PORT = 80 -# MAIN_SERVER.SETTING.worker_num = 80 - -################ DEFAULT CONFIG ################## - -SERVER_NAME = EasySwoole - -MAIN_SERVER.LISTEN_ADDRESS = 0.0.0.0 -MAIN_SERVER.PORT = 9501 -MAIN_SERVER.SERVER_TYPE = WEB_SOCKET_SERVER ## 可选为 SERVER WEB_SERVER WEB_SOCKET_SERVER -MAIN_SERVER.SOCK_TYPE = SWOOLE_TCP ## 该配置项当为SERVER_TYPE值为TYPE_SERVER时有效 -MAIN_SERVER.RUN_MODEL = SWOOLE_PROCESS - -MAIN_SERVER.SETTING.worker_num = 8 -MAIN_SERVER.SETTING.max_request = 5000 -MAIN_SERVER.SETTING.task_worker_num = 8 -MAIN_SERVER.SETTING.task_max_request = 500 -MAIN_SERVER.SETTING.document_root = EASYSWOOLE_ROOT/Static -MAIN_SERVER.SETTING.enable_static_handler = true - -MAIN_SERVER.SETTING.heartbeat_idle_time = 600 # 10分钟无操作则掉线 -MAIN_SERVER.SETTING.heartbeat_check_interval = 60 # 每隔一分钟检查一次 - -TEMP_DIR = null -LOG_DIR = null - -CONSOLE.ENABLE = true -CONSOLE.LISTEN_ADDRESS = 127.0.0.1 -CONSOLE.HOST = 127.0.0.1 -CONSOLE.PORT = 9500 -CONSOLE.EXPIRE = 120 -CONSOLE.AUTH = null -CONSOLE.PUSH_LOG = true - -################ SYSTEM CONFIG ##################### - -SYSTEM.WS_SERVER_PATH = ws://127.0.0.1:9501 -SYSTEM.LAST_MESSAGE_MAX = 10 - -################ REDIS CONFIG ##################### - -REDIS.HOST = 127.0.0.1 -REDIS.PORT = 6379 -# REDIS.AUTH =