diff --git a/lib/HTTPCurl.php b/lib/HTTPCurl.php index 5e72b15..d3a42f5 100644 --- a/lib/HTTPCurl.php +++ b/lib/HTTPCurl.php @@ -73,7 +73,7 @@ class HTTPCurl { } curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->timeout * 1000)); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000); } public static function error_string_from_code($code) { diff --git a/public/index.php b/public/index.php index 5ed72d1..df9073b 100644 --- a/public/index.php +++ b/public/index.php @@ -2,6 +2,8 @@ chdir('..'); include('vendor/autoload.php'); +register_shutdown_function('shutdown'); + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $router = new League\Route\RouteCollection; @@ -29,3 +31,20 @@ try { $response->setContent("Method not allowed\n"); $response->send(); } + +function shutdown() { + $error = error_get_last(); + if($error['type'] !== 0) { + header('HTTP/1.1 500 Server Error'); + header('X-PHP-Error-Type: '.$error['type']); + header('X-PHP-Error-Message: '.$error['message']); + header('Content-Type: application/json'); + echo json_encode([ + 'error' => 'internal_error', + 'error_code' => 500, + 'error_description' => $error['message'], + 'debug' => 'Please file an issue with any information you have about what caused this error: https://github.com/aaronpk/XRay/issues' + ]); + die(); + } +}