add register_shutdown_function

This commit is contained in:
Namhyeon Go 2024-06-21 14:21:51 +09:00
parent 61458e20b6
commit 56759a7fa7
2 changed files with 41 additions and 15 deletions

View File

@ -65,7 +65,7 @@ sudo update-ca-certificates
### Pan Arts
#### @yeohangdang@i.peacht.art
#### [#](@yeohangdang@i.peacht.art)
![Caterpillar Project Pan Art by @yeohangdang@i.peacht.art](assets/img/logo.png)
## Report abuse

View File

@ -9,7 +9,7 @@
* Updated at: 2024-06-21
*/
define("PHP_HTTPPROXY_VERSION", "0.1.5.19");
define("PHP_HTTPPROXY_VERSION", "0.1.5.20");
define("DEFAULT_SOCKET_TIMEOUT", 1);
define("STATEFUL_SOCKET_TIMEOUT", 30);
define("MAX_EXECUTION_TIME", 0);
@ -53,9 +53,35 @@ function jsonrpc2_error_encode($error, $id = '') {
return json_encode($data);
}
// https://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-e-error-error
// https://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code
function fatal_handler() {
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
if($error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
header("HTTP/1.1 200 OK");
exit(jsonrpc2_error_encode(array(
"status" => 503,
"code" => $errno,
"message"=> "Error occurred in file '$errfile' at line $errline: $errstr"
)));
}
}
register_shutdown_function("fatal_handler");
// https://stackoverflow.com/questions/16934409/curl-as-proxy-deal-with-https-connect-method
// https://stackoverflow.com/questions/12433958/how-to-parse-response-headers-in-php
function parse_headers($str) { // Parses HTTP headers into an array
// https://stackoverflow.com/questions/16934409/curl-as-proxy-deal-with-https-connect-method
// https://stackoverflow.com/questions/12433958/how-to-parse-response-headers-in-php
$headers = array();
$lines = preg_split("'\r?\n'", $str);