diff options
-rw-r--r-- | it_url.class | 12 | ||||
-rwxr-xr-x | test/it_url.t | 11 |
2 files changed, 7 insertions, 16 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 diff --git a/test/it_url.t b/test/it_url.t index c147acc..192db26 100755 --- a/test/it_url.t +++ b/test/it_url.t @@ -132,14 +132,9 @@ is( $_SERVER['PHP_SELF'] = $php_self; -$url = new it_url('http://www.gna.ch/'); -is((bool)$url->is_reachable(), true, "is_reachable($url->url)"); - -$url = new it_url('http://www.search.ch/not_found'); -is((bool)$url->is_reachable(), false, "is_reachable($url->url)"); - -$url = new it_url('http://bogus.url'); -is((bool)$url->is_reachable(), false, "is_reachable($url->url)"); +is(it_url::is_reachable('http://www.gna.ch/'), true, "is_reachable('http://www.gna.ch/')"); +is(it_url::is_reachable('http://www.search.ch/not_found'), false, "is_reachable('http://www.search.ch/not_found')"); +is(it_url::is_reachable('http://bogus.url'), false, "is_reachable('http://bogus.url')"); $response = it_url::get(['url' => 'http://www.gna.ch/', 'assoc' => true]); ok( |