From 2212237752b6684ee27c0632ec5e417654e8c19e Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sat, 24 Aug 2019 18:56:20 +0000 Subject: [PATCH] tcpclient : return the error codes of exception with codes : 521 Server Is Down Origin server refuse the connection 522 Connection Timed Out Could not negotiate a TCP handshake with the origin server. 523 Origin Is Unreachable Could not reach the origin server; for example, if the DNS records for the origin server are incorrect, or No route to host git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5441 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- tcpclient.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tcpclient.php b/tcpclient.php index f66a80f..ef86827 100644 --- a/tcpclient.php +++ b/tcpclient.php @@ -74,7 +74,7 @@ class tcpclient $nsRecords = @dns_get_record ($ipOrName, DNS_CNAME); if ($nsRecords === false || $nsRecords == array ()) throw new \Exception ("Can not find the IP for $ipOrName : ". - "DNS Error (No A, AAAA, CNAME entries)", 404); + "DNS Error (No A, AAAA, CNAME entries)", 523); } foreach ($nsRecords as $val) { @@ -172,6 +172,15 @@ class tcpclient $this->socket = $socket; return $this->socket; } + if ($errno === 110) + throw new \Exception ("Can not connect to server $this->ipOrName : ". + "Connection timed out", 522); + if ($errno === 111) + throw new \Exception ("Can not connect to server $this->ipOrName : ". + "Connection refused", 521); + if ($errno === 113) + throw new \Exception ("Can not connect to server $this->ipOrName : ". + "No route to host", 523); throw new \Exception ("Can not connect to server $this->ipOrName : ". $errstr, 500); }