summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2014-04-08 16:53:15 +0200
committerUrban Müller2014-04-08 16:53:15 +0200
commit326ac6b999b0a12a4da71e88b14a3011b4b2afb4 (patch)
tree000ca9e693b098aa5658caeca2db8d18facc2d8d
parentb1598bf64b8c29c9c0aed0d3570b60a722feb52d (diff)
downloaditools-326ac6b999b0a12a4da71e88b14a3011b4b2afb4.tar.gz
itools-326ac6b999b0a12a4da71e88b14a3011b4b2afb4.tar.bz2
itools-326ac6b999b0a12a4da71e88b14a3011b4b2afb4.zip
optional error reporting for it_url::get failures
-rw-r--r--it_url.class10
1 files changed, 7 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class
index 7042598..99fa395 100644
--- a/it_url.class
+++ b/it_url.class
@@ -215,14 +215,15 @@ function is_reachable($timeout = 5)
}
/**
- * Get simple URL with timeout. Can be called statically
+ * Get simple URL with timeout and one retry. Can be called statically
*
* 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['headers']: optional array of HTTP headers to send
- * @param $p['timeout']: timeout per read in seconds, defaults to 5. fractions allowed
+ * @param $p['timeout']: timeout per read in seconds, defaults to 5. fractions allowed. silent, see $p['safety']
+ * @param $p['safety']: set to 1 to generate an it::error in case of timeout
* @param $p['totaltimeout']: timeout for the whole function call
* @param $p['maxlength']: maximum length of response
* @param $p['filemtime']: Add HTTP header to only fetch when newer than this, otherwise return true instead of data
@@ -293,7 +294,7 @@ function request($p=array())
$p['timeout'] = min($p['timeout'], $p['totaltimeout']); # No operation may be longer than totaltimeout
$endtime = time() + $p['totaltimeout'];
- if ($fp = @fsockopen($url->realhostname, $url->port, $dummy_errno, $dummy_errstr, $p['timeout']))
+ if ($fp = @fsockopen($url->realhostname, $url->port, $dummy_errno, $errstr, $p['timeout']))
{
# urlencode data pairs if is array
if (is_array($p['data']))
@@ -373,6 +374,9 @@ function request($p=array())
if (time() >= $endtime)
$result = false;
+ if ($result === false && $p['safety'] == 1)
+ it::error("problem (timeout?) getting " . $p['url'] . " " . $errstr);
+
if ($p['maxlength'] && (strlen($this->data) + $len > $p['maxlength']))
$result = false;