Skip to content

Commit

Permalink
Improve exception handling for socket errors
Browse files Browse the repository at this point in the history
Per suggestion by @stof
  • Loading branch information
EvanDotPro committed Sep 18, 2012
1 parent a8280ef commit 0a337d0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Sslurp/MozillaCertData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://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);
}

Expand Down

0 comments on commit 0a337d0

Please sign in to comment.