I have a simple php library https://github.com/MonsterGfx/PHP-MPD-Client
It's work fine with my symfony2, but until mpd server is offline. I want to check mpd status -
static function checkSource(\MDS\SiteBundle\Entity\Source $source)
{
try {
MPD::connect($source->getMpdpassword(), $source->getMpdhost(), $source->getMpdport());
} catch (MPDConnectionFailedException $e) {
return false;
}
$ping = MPD::send("ping");
if ($ping['status'] == 'OK') {
return true;
} else {
return false;
}
}
Problem is when server is offline, I get throw
Warning: fsockopen(): unable to connect to planeset.ru:6600 (Connection refused) 500 Internal Server Error - ContextErrorException
But I have to catch error. I see the code in the library
if(!static::$fp)
{
// no connection
throw new MPDConnectionFailedException("$errstr ($errno)");
}
Why I can't catch error and have a 500 error ? What I do wrong way ?