summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
authorNathan Gass2023-10-30 15:46:33 +0100
committerNathan Gass2023-10-30 15:46:33 +0100
commitf471ee2b21d1dd24945ead7f38a3254585408991 (patch)
tree283cf79b29e3f107b40f6cd1c5621902d303f9f8 /it_url.class
parentaeb4710c7237f41a6f8eec2beac0b5ce9e31c9e1 (diff)
downloaditools-f471ee2b21d1dd24945ead7f38a3254585408991.tar.gz
itools-f471ee2b21d1dd24945ead7f38a3254585408991.tar.bz2
itools-f471ee2b21d1dd24945ead7f38a3254585408991.zip
change it_url::is_reachable to static api consistent with it_url::get
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class12
1 files changed, 4 insertions, 8 deletions
diff --git a/it_url.class b/it_url.class
index 1b90344..ad28f2c 100644
--- a/it_url.class
+++ b/it_url.class
@@ -68,15 +68,13 @@ function __construct($url = null)
/**
* Check if a given url (currently http:port80-only) can be fetched
* Note: Redirects are treated as succesful
- * $timeout Timeout for connection in seconds
+ * @param $p parameter array passed on to get
* @return true if url could be fetched
*/
-function is_reachable($timeout = 5)
+static function is_reachable($p = [])
{
- $url = new it_url($this->url);
- @$url->_get(['method' => 'HEAD', 'totaltimeout' => $timeout]);
-
- return $url->result >= 200 && $url->result < 400;
+ $result = static::get((is_array($p) ? $p : ['url' => $p]) + ['method' => 'HEAD', 'totaltimeout' => 5, 'assoc' => true, 'it_error' => false]);
+ return $result['status'] >= 200 && $result['status'] < 400;
}
# internal
@@ -91,8 +89,6 @@ static function _postprocess($data, $p)
/**
* Get simple URL with timeout and one retry. Can be called statically. Times out, calls it::error for all errs
*
- * If the protocol is not http, only features of get_multi are supported.
- *
* @param $p parameter array with the following keys
* @param $p['url'] url to get, defaults to constructor URL
* @param $p['assoc'] Return [ 'data' => string, 'status' => int, 'cookies' => array, 'headers' => array, 'errstr' => string ] instead of just data