summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-11-05 20:25:55 +0100
committerSimon Rettberg2013-11-05 20:25:55 +0100
commite277baed387b642bb7e6707b49e55da4719a9c79 (patch)
tree350343881ddc35fe53862e971506bc405a9a7fad /inc/util.inc.php
parentTolle neue APIs Sachen (diff)
downloadslx-admin-e277baed387b642bb7e6707b49e55da4719a9c79.tar.gz
slx-admin-e277baed387b642bb7e6707b49e55da4719a9c79.tar.xz
slx-admin-e277baed387b642bb7e6707b49e55da4719a9c79.zip
Working on download of remote configs
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index f456d164..591c7e79 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -72,5 +72,29 @@ class Util
return nl2br($string);
}
+ /**
+ * Download file, obey given timeout in seconds
+ * Return data on success, false on failure
+ */
+ function download($url, $timeout, &$code) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, ceil($timeout / 2));
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ $data = curl_exec($ch);
+ $data = explode("\r\n\r\n", $data, 2);
+ if (preg_match('#^HTTP/\d+\.\d+ (\d+) #', $data[0], $out)) {
+ $code = (int)$out[1];
+ } else {
+ $code = 999;
+ }
+ curl_close($ch);
+ if (count($data) < 2) return '';
+ return $data[1];
+ }
+
}