I am writing a socket client that connects to a server and does some interfacing, gets a result, and closes. However, sometime that server may be down or unavailable, and I want to show my users a nice screen showing that the system is currently down.
How would I handle that instead of having it spew all these warnings? I assume try/catch will not work since it's not actually throwing an exception.
I read dozens of answers, but they all involved a global warning handler, which I can't use for 2 reasons: I wanna know what went wrong, and I don't wanna call it a gazillion times (usually if something goes wrong, a lot of things goes wrong).
Warning: socket_connect(): unable to connect [10061]: No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\TCPServices\Sockets.php on line 7
Warning: socket_write() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\TCPServices\Sockets.php on line 18
Warning: socket_read() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\TCPServices\Sockets.php on line 24
Warning: socket_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\TCPServices\Sockets.php on line 31