我有一个随机的问题,我无法缩小范围.偶尔,我会在Symfony2应用程序中收到以下错误:
Uncaught Exception: An exception occured in driver: SQLSTATE[08004] [1040] Too many connections {“type”:1,”file”:”/var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php”,”line”:115,”level”:30709
我想设置一个应用程序范围的侦听器来捕获PDOException并记录一些信息.如何挂钩到Symfony才能捕获PDOException?
解决方法:
您需要创建自定义异常侦听器.它将侦听所有异常,但您将在其中指定类型检查.
在您的services.yml中,您需要指定监听器:
kernel.listener.your_pdo_listener:
class: Acme\AppBundle\EventListener\YourExceptionListener
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onPdoException }
现在您需要创建此类:
YourExceptionListener:
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class YourExceptionListener
{
public function onPdoException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof PDOException) {
//now you can do whatever you want with this exception
}
}
}
标签:doctrine-orm,php,symfony,pdo,doctrine
来源: https://codeday.me/bug/20191007/1867126.html
Symfony PDOException 监听
1070

被折叠的 条评论
为什么被折叠?



