请问下,我在基本开发模型下使用PDO链接mysql,出现错误时,直接被exit了,我trycatch也没用,怎么办?

498621

请问下,我在基本开发模型下使用PDO链接mysql,出现错误时,直接被exit了,我trycatch也没用,怎么办?

exception 'PDOException' with message 'SQLSTATE: Integrity constraint violation: 1062 Duplicate entry 'huayz' for key 'user'' in /root/new_workerman/applications/Game/core/DbConnection.class.php:1583 Stack trace: #0 /root/new_workerman/applications/Game/core/DbConnection.class.php(1583): PDOStatement->execute() #1 /root/new_workerman/applications/Game/core/DbConnection.class.php(1664): DbConnection->execute('INSERT INTO `us...', Array) #2 /root/new_workerman/applications/Game/control/index.ctl.php(60): DbConnection->query() #3 /root/new_workerman/applications/Game/index.php(32): IndexControl->register() #4 /root/new_workerman/workerman/Common/WebServer.php(223): include('/root/new_worke...') #5 /root/new_workerman/workerman/Core/SocketWorker.php(412): WebServer->dealProcess('GET /?a=registe...') #6 : Man\Core\SocketWorker->dealInputBase(Resource id #58, 1, 58) #7 /root/new_workerman/workerman/Core/Events/Select.php(190): call_user_func_array(Array, Array) #8 /root/new_workerman/workerman/Core/SocketWorker.php(242): Man\Core\Events\Select->loop() #9 /root/new_workerman/workerman/Core/Master.php(446): Man\Core\SocketWorker->start() #10 /root/new_workerman/workerman/Core/Master.php(360): Man\Core\Master::createOneWorker('StatisticWeb') #11 /root/new_workerman/workerman/Core/Master.php(639): Man\Core\Master::spawnWorkers() #12 /root/new_workerman/workerman/Core/Master.php(579): Man\Core\Master::checkWorkerExit() #13 /root/new_workerman/workerman/Core/Master.php(186): Man\Core\Master::loop() #14 /root/new_workerman/workerman/bin/workermand(115): Man\Core\Master::run() #15 {main}
7235 2 0
2个回答

498621

任何mysql边的错误, connect失败, insert失败 都这样返回一坨数据
workerman进程告诉我:
WORKER EXIT UNEXPECTED

这样错误根本没法捕捉和提示用户 请教下这该怎么办?

  • 暂无评论
walkor 打赏

看起来你使用的是workerman的webserver
数据库的这个异常不会导致进程退出,看起来是你并没有捕获这个异常,这个异常被workerman的webserver捕获了,并打印出来

WORKER EXIT UNEXPECTED一般是两个原因(抛异常不会导致进程退出)
1、代码中使用了exit die语句,如果是webserver开发,请使用Man\Common\Protocols\Http\jump_exit()代替
2、代码有致命错误,例如语法错误、调用了不存在的函数等等,这种错误在workerman/log下会有具体的错误日志

如果是web开发,也可以选择用传统的nginx/apache+PHP开发模式,这样能很好的结合现有的mvc框架(tp yii...)。而网页上的即时socket通讯(如websocket通讯)后台使用workerman来做

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