When I call fsockopen to an unreachable IP address, PHP stops execution with FATAL ERROR, as it is intended to do. But it's normal situation for me, that a host is unreachable. Is there a way, how to prevent stopping the php even in case of the FATAL ERROR, if it is the intended behavior?
I don't use any framework, I handle all errors myself. I registers the handlers like this:
set_error_handler("errorHandler");
register_shutdown_function("fatalErrorHandler");
and the handlers are defined like this:
function fatalErrorHandler()
{
$error = error_get_last();
if( $error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
errorHandler($errno, "FATAL: " . $errstr, $errfile, $errline,get_defined_vars(),debug_backtrace());
}
}
function errorHandler($errno, $errstr, $errfile, $errline,$vars,$trace="")
{
// some formatting and checking
file_put_contents(dirname(__FILE__) . "/error/" . gmdate("YmdHis") . str_replace(".","",microtime(true)) . ".err"
,"<error_log_date>" . gmdate("YmdHis") . "</error_log_date><error_log_uid>{$uid}</error_log_uid>
<error_log_str>{$errstr}</error_log_str>
<error_log_file>{$errfile}</error_log_file>
<error_log_line>{$errline}</error_log_line>
<error_log_vars>{$vars}</error_log_vars>
<error_log_trace>{$trace}</error_log_trace>");
return true;
}