0

期望的事workerstart中捕获到继承接口参数确实这个错误,但是没有捕获到

clipboard.png

server.php

class server{
    public function onWorkerStart($server,$rid){
        try{
            include "./class.php";
        }catch(\Exception $e){
            var_dump($e->getMessage());
        }catch(\throwable $e){
            var_dump($e->getMessage());
        }
    }

    public function onReceive($server,$fd,$rid,$data){
    }
}
$serv = new \Swoole\Server("0.0.0.0",9501);
$serv->set([
    'worker_num' => 3,
    'daemonize' => false,
]);
$server = new server;
$serv->on('workerStart',[$server,'onWorkerStart']);
$serv->on('receive',[$server,'onReceive']);
$serv->start();

class.php

<?php

interface IT {
    public function run(array $conf);
}

class ITT implements IT {
    public function run(){
        echo 1;
    }
}

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

你期待的结果是什么?实际看到的错误信息又是什么?

2019-07-09 提问
1 个回答
0

试试 register_shutdown_function

<?php
class server{
    public function onWorkerStart($server,$rid){
        try{
            include "class.php";
            throw new \Exceptn('aaa');
        }catch(\Exception $e){
            var_dump('e_'.$e->getMessage());
        }catch(\throwable $e){
            var_dump('t_'.$e->getMessage());
        }
    }
    public function onReceive($server,$fd,$rid,$data){
    }
}
$serv = new \Swoole\Server("0.0.0.0",9501);
$serv->set([
    'worker_num' => 1,
    'daemonize' => false,
]);
$server = new server;
register_shutdown_function('handleFatal');
$serv->on('workerStart',[$server,'onWorkerStart']);
$serv->on('receive',[$server,'onReceive']);
$serv->start();


function handleFatal()
{
    $error = error_get_last();
    var_dump($error);
}

撰写答案

推广链接