您需要创建自定义异常监听。它会监听所有的异常,但你会在其中指定类型检查。
在你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
}
}
}
检查文档how to create event listener
这是非常有帮助,谢谢。 –
这就是事实。你的错误说太多的连接,必须在mysql服务器端配置。 –
如果您已阅读我的问题,您可以看到我正在尝试设置侦听器来调试问题,以便我可以修复服务器。它已经被配置为接受400个连接,所以发生了一些事情导致它锁定,这就是为什么我问这个问题。你的回答确实没有帮助。 –