I am using phpseclib and if there is no connection to the server a "user_error" is thrown.
The code to simulate the problem in a Artisan Command - just use an nonexistig IP and you can simulate the problem:
public function fire()
{
try {
$sshCon=SSH::into('myServer')->getGateway()->getConnection();
} catch(RuntimeException $e) {
$this->error($e->getMessage());
Log::error($e);
}
}
The Error Msg:
Cannot connect to XXX.XXX.XX.XX:22. Error 51. Network is unreachable
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Connection closed prematurely' in /SVN-Checkouts/project/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:3126
How can I catch this error?
I have tired to add this to /app/start/artisan.php
:
App::error(function(ErrorException $exception) {
Log::error($exception);
});
App::fatal(function($exception)
{
Log::error($exception);
});
When I debug the app - the user_error is converted into an ErrorException which is thrown by the app but non of my custom error Handler gets called.
PHP Fatal Error stops execution of the script, so you can't catch it.
Docs: http://php.net/manual/en/errorfunc.constants.php
Stackoverflow: http://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-error http://stackoverflow.com/questions/4410632/handle-fatal-errors-in-php-using-register-shutdown-function
Hope it helps!
Best
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community