GatewayWorker,连接异步客户端报错[已解决]

嘻嘻哈哈

问题描述

使用AsyncTcpConnection异步连接wss服务端,一直报错。php环境使用的是php8.2,文件是从Workerman官网下载的(https://www.workerman.net/download

我换成本地的php7.2环境后,可以正常连接

报错内容如下:
SSL handshake error: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

程序代码

if ($businessWorker->id == 0) {

            $db = new DbConnection('127.0.0.1', '3306', 'root', 'test', 'test');

            $option = $db->select('code')
                         ->from('test')
                         ->limit(4)
                         ->offset(0)
                         ->query();

            $db->closeConnection();

            if (!isset($option)) {
                return;
            }

            $code = implode(",",array_keys($option));

            global $redis;

            $redis = new redis();
            $redis->connect('127.0.0.1', 6379);

            $con = new AsyncTcpConnection('ws://test.cn:443');
            $con->transport = 'ssl';

//            $contextOptions = [
//                'ssl' => [
//                    'verify_peer' => false,
//                    'verify_peer_name' => false
//                ]
//            ];
//            $con->context = $contextOptions;

            $con->onConnect = function ($con) use ($code)
            {
                echo "连接成功";
            };

            $con->onMessage = function ($con, $message) use ($option)
            {
                $data = json_decode($message, true);

                // 如果消息数达到1000
                static $request_count = 0;
                if(++$request_count >= self::MAX_REQUEST)
                {
                    /*
                     * 退出当前进程,主进程会立刻重新启动一个全新进程补充上来
                     * 从而完成进程重启
                     */
                    Worker::stopAll();
                }
            };

            $con->onClose = function ($con)
            {
                Timer::del($con->timer_id);
                $con->reConnect(1);
            };

            $con->connect();
        }

解决了,指定php.ini文件即可

./php82 -c php.ini

731 0 0
0个回答

年代过于久远,无法发表回答
×
🔝