From 0a337d00d11869f8c2e55e0ed0032954ca1f8e11 Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Tue, 18 Sep 2012 09:11:07 -0700 Subject: [PATCH] Improve exception handling for socket errors Per suggestion by @stof --- src/Sslurp/MozillaCertData.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Sslurp/MozillaCertData.php b/src/Sslurp/MozillaCertData.php index 2afeca6..69729d9 100644 --- a/src/Sslurp/MozillaCertData.php +++ b/src/Sslurp/MozillaCertData.php @@ -79,13 +79,18 @@ protected function fetchLatestCertData($until = false) { $ctx = $this->getStreamContext(); - set_error_handler(function ($code, $msg) { - throw new \RuntimeException($msg, $code); + set_error_handler(function ($code, $message, $filename, $lineno, $context) { + if ($error_reporting() & $level) { + throw new \ErrorException(sprintf('%s: %s in %s line %d', $code, $message, $filename, $lineno), $code, 0, $filename, $lineno); + } + + return false; }); try { $fp = stream_socket_client('ssl://mxr.mozilla.org:443', $errNo, $errStr, 30, STREAM_CLIENT_CONNECT, $ctx); - } catch (\RuntimeException $e) { + } catch (\ErrorException $e) { + restore_error_handler(); throw new \RuntimeException($errStr, $errNo, $e); }