Answer the question
In order to leave comments, you need to log in
How to catch ErrorException on fsockopen() error in Yii2?
I open the socket in the most usual way:
$socket = fsockopen("tcp://$hostname", $port, $errno, $errstr, 3);
$socket == false
PHP Warning - yii\base\ErrorException
fsockopen(): unable to connect to tcp://<...> (Connection refused)
try {
$socket = fsockopen("tcp://$hostname", $port, $errno, $errstr, 3);
// do something
fclose($socket);
} catch(ErrorException $e) {
// do nothing
}
Answer the question
In order to leave comments, you need to log in
This is how it seems to work:
$errno = null;
$errstr = null;
try {
$socket = fsockopen("tcp://127.0.0.1", 8085, $errno, $errstr, 3);
fclose($socket);
} catch(\ErrorException $e) {
var_dump(get_class($e));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question