异步 MySQL Redis 阿里云上使用异常,求解!

zxyfax

在本机(mac)上运行正常:

链接配置如下:

$worker->onWorkerStart = function () {
    global $mysql;
    global $factory;

    // 获得workerman的event-loop,
    $loop = Worker::getEventLoop();

    // Redis
    $factory = new Factory($loop);
    // 连接参数
    $mysql = new React\MySQL\Connection($loop, );
    $mysql->on('error', function ($e) {
        echo $e;
    });
    $mysql->connect(function ($e) {
        if ($e) {
            echo $e;
        } else {
            echo "mysql connect success\n";
        }
    });

异常报错如下:

exception 'React\Dns\RecordNotFoundException' with message 'DNS Request did not return valid answer.' in /Data/htdocs/SEMAC/Workerman/vendor/react/dns/src/Resolver/Resolver.php:41
Stack trace:
#0 /Data/htdocs/SEMAC/Workerman/vendor/react/dns/src/Resolver/Resolver.php(29): React\Dns\Resolver\Resolver->extractAddress(Object(React\Dns\Query\Query), Object(React\Dns\Model\Message))
#1 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/FulfilledPromise.php(25): React\Dns\Resolver\Resolver->React\Dns\Resolver\{closure}(Object(React\Dns\Model\Message))
#2 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(119): React\Promise\FulfilledPromise->then(Object(Closure), NULL)
#3 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(174): React\Promise\Promise->React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#4 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(133): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#5 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(192): React\Promise\Promise->resolve(Object(React\Dns\Model\Message))
#6 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/FulfilledPromise.php(39): React\Promise\Promise->React\Promise\{closure}(Object(React\Dns\Model\Message))
#7 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(120): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#8 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(174): React\Promise\Promise->React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#9 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(133): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#10 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(192): React\Promise\Promise->resolve(Object(React\Dns\Model\Message))
#11 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/FulfilledPromise.php(39): React\Promise\Promise->React\Promise\{closure}(Object(React\Dns\Model\Message))
#12 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(120): React\Promise\FulfilledPromise->done(Object(Closure), Object(Closure), Object(Closure))
#13 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(174): React\Promise\Promise->React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#14 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(133): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#15 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(192): React\Promise\Promise->resolve(Object(React\Dns\Model\Message))
#16 : React\Promise\Promise->React\Promise\{closure}(Object(React\Dns\Model\Message))
#17 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Deferred.php(35): call_user_func(Object(Closure), Object(React\Dns\Model\Message))
#18 /Data/htdocs/SEMAC/Workerman/vendor/react/dns/src/Query/Executor.php(94): React\Promise\Deferred->resolve(Object(React\Dns\Model\Message))
#19 : React\Dns\Query\Executor->React\Dns\Query\{closure}('\x02\v\x81\x83\x00\x01\x00\x00\x00\x01\x00\x00\tlo...', Object(React\Socket\Connection))
#20 /Data/htdocs/SEMAC/Workerman/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(65): call_user_func_array(Object(Closure), Array)
#21 /Data/htdocs/SEMAC/Workerman/vendor/react/stream/src/Stream.php(170): Evenement\EventEmitter->emit('data', Array)
#22 : React\Stream\Stream->handleData(Resource id #62, Object(Workerman\Events\React\StreamSelectLoop))
#23 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/StreamSelectLoop.php(232): call_user_func(Array, Resource id #62, Object(Workerman\Events\React\StreamSelectLoop))
#24 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(997540.95077515)
#25 /Data/htdocs/SEMAC/Workerman/Events/React.php(98): React\EventLoop\StreamSelectLoop->run()
#26 /Data/htdocs/SEMAC/Workerman/Worker.php(1521): Workerman\Events\React->loop()
#27 /Data/htdocs/SEMAC/Workerman/Worker.php(932): Workerman\Worker->run()
#28 /Data/htdocs/SEMAC/Workerman/Worker.php(895): Workerman\Worker::forkOneWorker(Object(Workerman\Worker))
#29 /Data/htdocs/SEMAC/Workerman/Worker.php(427): Workerman\Worker::forkWorkers()
#30 /Data/htdocs/SEMAC/server.php(414): Workerman\Worker::runAll()

exception 'React\Dns\Query\TimeoutException' with message 'DNS query for localhost timed out' in /Data/htdocs/SEMAC/Workerman/vendor/react/dns/src/Query/Executor.php:69
Stack trace:
#0 : React\Dns\Query\Executor->React\Dns\Query\{closure}(Object(React\EventLoop\Timer\Timer))
#1 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/Timer/Timers.php(90): call_user_func(Object(Closure), Object(React\EventLoop\Timer\Timer))
#2 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/StreamSelectLoop.php(177): React\EventLoop\Timer\Timers->tick()
#3 /Data/htdocs/SEMAC/Workerman/Events/React.php(98): React\EventLoop\StreamSelectLoop->run()
#4 /Data/htdocs/SEMAC/Workerman/Worker.php(1521): Workerman\Events\React->loop()
#5 /Data/htdocs/SEMAC/Workerman/Worker.php(932): Workerman\Worker->run()
#6 /Data/htdocs/SEMAC/Workerman/Worker.php(895): Workerman\Worker::forkOneWorker(Object(Workerman\Worker))
#7 /Data/htdocs/SEMAC/Workerman/Worker.php(427): Workerman\Worker::forkWorkers()
#8 /Data/htdocs/SEMAC/server.php(414): Workerman\Worker::runAll()
#9 {main}
3513 3 0
3个回答

walkor

数据库参数用ip,不要用localhost域名。

  • 暂无评论
zxyfax

嗯,我试过了,用IP会报另一个错误。 Connection refused

exception 'React\SocketClient\ConnectionException' with message 'Connection refused' in /Data/htdocs/SEMAC/Workerman/vendor/react/socket-client/src/Connector.php:75
Stack trace:
#0 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/FulfilledPromise.php(25): React\SocketClient\Connector->checkConnectedSocket(Resource id #56)
#1 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(119): React\Promise\FulfilledPromise->then(Array, NULL)
#2 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(174): React\Promise\Promise->React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#3 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(133): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#4 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Promise.php(192): React\Promise\Promise->resolve(Resource id #56)
#5 : React\Promise\Promise->React\Promise\{closure}(Resource id #56)
#6 /Data/htdocs/SEMAC/Workerman/vendor/react/promise/src/Deferred.php(35): call_user_func(Object(Closure), Resource id #56)
#7 /Data/htdocs/SEMAC/Workerman/vendor/react/socket-client/src/Connector.php(64): React\Promise\Deferred->resolve(Resource id #56)
#8 : React\SocketClient\Connector->React\SocketClient\{closure}(Resource id #56, Object(Workerman\Events\React\StreamSelectLoop))
#9 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/StreamSelectLoop.php(240): call_user_func(Object(Closure), Resource id #56, Object(Workerman\Events\React\StreamSelectLoop))
#10 /Data/htdocs/SEMAC/Workerman/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(999963.99879456)
#11 /Data/htdocs/SEMAC/Workerman/Events/React.php(98): React\EventLoop\StreamSelectLoop->run()
#12 /Data/htdocs/SEMAC/Workerman/Worker.php(1521): Workerman\Events\React->loop()
#13 /Data/htdocs/SEMAC/Workerman/Worker.php(932): Workerman\Worker->run()
#14 /Data/htdocs/SEMAC/Workerman/Worker.php(895): Workerman\Worker::forkOneWorker(Object(Workerman\Worker))
#15 /Data/htdocs/SEMAC/Workerman/Worker.php(427): Workerman\Worker::forkWorkers()
#16 /Data/htdocs/SEMAC/server.php(414): Workerman\Worker::runAll()
  • 暂无评论
zxyfax

我知道了,我服务器的MySQL是另一个端口,需要在

$mysql = new React\MySQL\Connection($loop, );

这里加入端口号.

  • 暂无评论
年代过于久远,无法发表回答
🔝