wilbur-yu/hyperf-server-switch

0.0.2 2022-04-26 11:55 UTC

This package is auto-updated.

Last update: 2022-06-26 12:24:29 UTC


README

搬运自: 如何让 Hyperf 只启动一个服务

安装

composer require wilbur-yu/hyperf-server-switch

配置

config/autoload/server.php

'servers' => [
        [
            'name'      => 'http',
            'type'      => Server::SERVER_HTTP,
            'host'      => '127.0.0.1',
            'port'      => 9801,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ],
        ],
        [
            'name'      => 'http2',
            'type'      => Server::SERVER_HTTP,
            'host'      => '0.0.0.0',
            'port'      => 9502,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => ['HttpServer2', 'onRequest'],
            ],
        ],
    ],

使用

  1. 启动所有 server
php bin/hyperf.php start
  1. 启动某个 server
php bin/hyperf.php -S http

// or

php bin/hyperf.php -S http2