DetectsLostConnections.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Illuminate\Database;
  3. use Throwable;
  4. use Illuminate\Support\Str;
  5. trait DetectsLostConnections
  6. {
  7. /**
  8. * Determine if the given exception was caused by a lost connection.
  9. *
  10. * @param \Throwable $e
  11. * @return bool
  12. */
  13. protected function causedByLostConnection(Throwable $e)
  14. {
  15. $message = $e->getMessage();
  16. return Str::contains($message, [
  17. 'server has gone away',
  18. 'no connection to the server',
  19. 'Lost connection',
  20. 'is dead or not enabled',
  21. 'Error while sending',
  22. 'decryption failed or bad record mac',
  23. 'server closed the connection unexpectedly',
  24. 'SSL connection has been closed unexpectedly',
  25. 'Error writing data to the connection',
  26. 'Resource deadlock avoided',
  27. 'Transaction() on null',
  28. 'child connection forced to terminate due to client_idle_limit',
  29. 'query_wait_timeout',
  30. 'reset by peer',
  31. 'Physical connection is not usable',
  32. 'TCP Provider: Error code 0x68',
  33. ]);
  34. }
  35. }