diff options
author | Christian Schneider | 2019-10-17 16:46:36 +0200 |
---|---|---|
committer | Christian Schneider | 2019-10-17 16:48:16 +0200 |
commit | 55597357c715484494bc7ef58ee36a6d0e5b63f6 (patch) | |
tree | 3785884562f9cb33c56b37144e7e555dc76bc0c2 /it_url.class | |
parent | 9f948f44cdc55b9cac093eb14b0e453901953075 (diff) | |
download | itools-55597357c715484494bc7ef58ee36a6d0e5b63f6.tar.gz itools-55597357c715484494bc7ef58ee36a6d0e5b63f6.tar.bz2 itools-55597357c715484494bc7ef58ee36a6d0e5b63f6.zip |
Fix ->is_reachable to use get() instead of fopen to use HTTP/1.1 and add tests
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/it_url.class b/it_url.class index d03ad07..c8fb796 100644 --- a/it_url.class +++ b/it_url.class @@ -71,19 +71,10 @@ function __construct($url = null) */ function is_reachable($timeout = 5) { - $result = false; - - if ($fp = @fsockopen($this->realhostname, $this->port, $dummy_errno, $dummy_errstr, $timeout)) - { - fputs($fp, "GET /$this->path HTTP/1.0\r\nHost: $this->realhostname\r\nUser-Agent: ITools\r\n\r\n"); - $line = fgets($fp, 128); - fclose($fp); + $url = new it_url($this->url); + @$url->get(['method' => 'HEAD', 'totaltimeout' => $timeout]); - #debug("it_url::is_reachable($this->rawurl: $line"); - $result = preg_match("#^$this->protocol/[^ ]+ +[23]#i", $line); - } - - return $result; + return $url->result >= 200 && $url->result < 400; } /** |