搬运自: 如何让 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'],
],
],
],
- 启动所有 server
php bin/hyperf.php start
- 启动某个 server
php bin/hyperf.php -S http
// or
php bin/hyperf.php -S http2