DetectsLostConnections.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Database;
  12. use Hyperf\Stringable\Str;
  13. use Throwable;
  14. trait DetectsLostConnections
  15. {
  16. /**
  17. * Determine if the given exception was caused by a lost connection.
  18. */
  19. protected function causedByLostConnection(Throwable $e): bool
  20. {
  21. $message = $e->getMessage();
  22. return Str::contains($message, [
  23. 'server has gone away',
  24. 'no connection to the server',
  25. 'Lost connection',
  26. 'is dead or not enabled',
  27. 'Error while sending',
  28. 'decryption failed or bad record mac',
  29. 'server closed the connection unexpectedly',
  30. 'SSL connection has been closed unexpectedly',
  31. 'Error writing data to the connection',
  32. 'Resource deadlock avoided',
  33. 'Transaction() on null',
  34. 'child connection forced to terminate due to client_idle_limit',
  35. 'query_wait_timeout',
  36. 'reset by peer',
  37. 'Physical connection is not usable',
  38. 'TCP Provider: Error code 0x68',
  39. 'Name or service not known',
  40. 'ORA-03114',
  41. 'Packets out of order. Expected',
  42. 'Broken pipe',
  43. 'Error reading result',
  44. // PDO::prepare(): Send of 77 bytes failed with errno=110 Operation timed out
  45. // SSL: Handshake timed out
  46. // SSL: Operation timed out
  47. // SSL: Connection timed out
  48. // SQLSTATE[HY000] [2002] Connection timed out
  49. 'timed out',
  50. // PDOStatement::execute(): Premature end of data
  51. 'Premature end of data',
  52. ]);
  53. }
  54. }