swoft icon indicating copy to clipboard operation
swoft copied to clipboard

RPC server 启动中不能集成 Http 服务

Open zhenhua2340 opened this issue 5 years ago • 1 comments

Q A
Bug report? yes
Feature request? no
Swoft version v2.0.10
Swoole version 4.5.5
PHP version 7.2.33
Runtime environment Docker

当启动 RPC 服务时,如果把 Http 一起启动的话就会报错

bean.php 文件

    'rpcServer'          => [
        'class' => ServiceServer::class,
        'port'     => 9606,
        'listener' => [
            'http' => bean('httpServer'),
        ]
    ],

执行:php bin/swoft rpc:start,报错:


                 SERVER INFORMATION(v2.0.10)
  **************************************************************
  * RPC      | Listen: 0.0.0.0:9606, Mode: Process, Worker: 1
  * HTTP     | Listen: 0.0.0.0:9605, (attached)
  **************************************************************

RPC Server Start Success!
2020/11/19-15:25:51 [INFO] Swoft\Server\Server:startSwoole(499) Swoole\Runtime::enableCoroutine
(CONSOLE)Swoft\Server\Exception\ServerException: Swoole task event listener is not Swoft\Server\Contract\SyncTaskInterface
At /mnt/test/swoft/vendor/swoft/server/src/Server.php line 636

注释下列代码能正常启动

    'httpServer'         => [
        ... ...
        'on'       => [
            // SwooleEvent::TASK   => bean(SyncTaskListener::class),  // Enable sync task
            // SwooleEvent::TASK   => bean(TaskListener::class),  // Enable task must task and finish event
            // SwooleEvent::FINISH => bean(FinishListener::class)
        ],

但访问 HTTP 的时候又报错:

PHP Fatal error:  Uncaught InvalidArgumentException: json_decode error: Syntax error in /mnt/test/swoft/vendor/swoft/stdlib/src/Helper/JsonHelper.php:36
Stack trace:
#0 /mnt/test/swoft/vendor/swoft/rpc/src/Packet/JsonPacket.php(69): Swoft\Stdlib\Helper\JsonHelper::decode('GET / HTTP/1.1\r...', true)
#1 /mnt/test/swoft/vendor/swoft/rpc/src/Packet.php(85): Swoft\Rpc\Packet\JsonPacket->decode('GET / HTTP/1.1\r...')
#2 /mnt/test/swoft/vendor/swoft/rpc-server/src/Request.php(122): Swoft\Rpc\Packet->decode('GET / HTTP/1.1\r...')
#3 /mnt/test/swoft/vendor/swoft/rpc-server/src/Swoole/ReceiveListener.php(41): Swoft\Rpc\Server\Request::new(Object(Swoole\Server), 1, 0, 'GET / HTTP/1.1\r...')
#4 {main}
  thrown in /mnt/test/swoft/vendor/swoft/stdlib/src/Helper/JsonHelper.php on line 36
PHP Fatal error:  Uncaught ErrorException: Uncaught InvalidArgumentException: json_decode error: Syntax error in /mnt/test/swoft/vendor/swoft/stdlib/src/Helper/JsonHelper.php:36

而启动 Http 服务时,如果把 Rpc 一起启动的话就正常,php bin/swoft http:start 正常启动,不会报错

bean.php 配置

    'httpServer'         => [
        'class'    => HttpServer::class,
        'port'     => 9605,
        'listener' => [
            'rpc' => bean('rpcServer')
        ],

zhenhua2340 avatar Nov 19 '20 07:11 zhenhua2340

Encountered the same problem, how can I deal with it later?

xwp93922 avatar Jun 09 '21 09:06 xwp93922