How to check server status?


Trying to check the status of the server through the socket. Everything is fine when the server is running, but as soon as I turn it off, then gets error:
socket_connect(): unable to connect [111]: Connection refused

How do I get rid of them? Know about the option with error_reporting () but is there no other way?

I want a boolean variable, and further with respect to true or folse display their own alerts.

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
 throw new \Exception('failed socket_create(): reason:' . socket_strerror(socket_last_error()));

$result = socket_connect($socket, $s_row['ip'], $s_row['port']);
if ($result === false) {
 throw new \Exception('failed socket_connect(). Reason: ($result) ' . socket_strerror(socket_last_error()));

September 18th 19 at 23:52
3 answers
September 18th 19 at 23:54
Turn off the error output.
or @socket_connect
Thank you very much. - Preston55 commented on September 18th 19 at 23:57
September 18th 19 at 23:56

In such operations simply suppress the error output.
It is not considered bad manners.
Thank you very much. - Preston55 commented on September 18th 19 at 23:59
September 18th 19 at 23:58
Have been using try { } catch?
And you think I just throw new writing?) He swears by another. Two options above helped. - Preston55 commented on September 19th 19 at 00:01

Find more questions by tags PHP