如何避免 PHP 中的 strace
我有 PHP + MySQL 代码库。如果 MySQL 停止并且在登录期间它会失败,如下所示:
Fatal error: Uncaught exception 'FrameworkException' with message 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' in /var/www/html/classes/class.connection.php:24
Stack trace: #0 /var/www/html/login.php(15): Connection::getInstance('localhost', 'user', '__password', 'DB') #1 /var/www/html/login.php(73): isDataValid('lakshmipathi.g@...', 'test') #2 {main} thrown in /var/www/html/classes/class.connection.php on line 24
如何避免此堆栈跟踪?我想避免在出现错误时像这样显示用户名和密码
I'm having PHP + MySQL code base. If MySQL is stopped and during log-in it fails like this:
Fatal error: Uncaught exception 'FrameworkException' with message 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' in /var/www/html/classes/class.connection.php:24
Stack trace: #0 /var/www/html/login.php(15): Connection::getInstance('localhost', 'user', '__password', 'DB') #1 /var/www/html/login.php(73): isDataValid('lakshmipathi.g@...', 'test') #2 {main} thrown in /var/www/html/classes/class.connection.php on line 24
How to avoid this stack trace? I want to avoid the username and password displayed like this in case of errors
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在生产服务器上,您应该使用 display_errors 隐藏错误php.ini 的 指令
错误仍会被记录,但不会显示给最终用户。
使用 error_reporting 关闭错误不是如果您需要调试,这是一个好主意
,但是您应该处理异常:
On a production server you should hide the error with the display_errors directive of your php.ini
The error still be logged but not displayed to the end user.
Turning off the error with error_reporting is not a good idea if you need to debug
Nevertheless you should handle the exception :
我建议使用@mysql_connect(或@+您调用的任何函数)来抑制任何错误消息。 并手动吐出一些错误。由于您正在使用某种神秘的框架,您可以简单地捕获异常。
但是,对于实时环境,您无论如何都应该禁用向用户报告任何类型的错误。
I'd recommend using
@mysql_connect
(or @ + whatever function you call) to suppress any error messages. And manually spit out some error. Since you are using some kind of mysterious framework, you could simply catch the exception.But, for live environments, you should disable any kind error reporting to the user anyway.