您需要創建自定義異常監聽。它會監聽所有的異常,但你會在其中指定類型檢查。
在你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個連接,所以發生了一些事情導致它鎖定,這就是爲什麼我問這個問題。你的回答確實沒有幫助。 –