forked from goldenice/GMOT-Whatpulse-Parser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
52 lines (43 loc) · 1.52 KB
/
functions.php
File metadata and controls
52 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
// hashes the string in sha1 using \n as newlines
function sha1Newline($str) {
return sha1(str_replace(array("\r", "\r\n"), "\n", $str));
}
// return file with 1 second timeout or return false
function readExternalFile($url) {
$handle = curl_init();
$addr = '';
if (isset($_SERVER['REMOTE_ADDR'])) {
$addr = $_SERVER['REMOTE_ADDR'];
} else {
$addr = gethostname() . ' (' . gethostbyname(gethostname()) . ')';
}
$headers = array(
'User-Agent' => 'GMOT-Whatpulse-Parser/1.0 just for logs (requested by ' . $addr . ' at ' . time() . ')',
);
if (DEVMODE || isset($_GET['devmode'])) {
echo 'Requesting external file (' . $url . ') ...' . ENDL;
$start = microtime(true);
}
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_TIMEOUT, 1);
$response = curl_exec($handle);
curl_close($handle);
if (DEVMODE || isset($_GET['devmode'])) {
if ($response === false) {
echo ' ... failed (timeout of 1 second?)' . ENDL . ENDL;
} else {
echo ' ... success (' . strlen($response) . ' characters, ' . round((microtime(true) - $start) * 1000, 2) . 'ms)' . ENDL . ENDL;
}
}
return $response;
}
function times($str, $count) {
$ret = $str;
for ($i = 1; $i < $count; $i++) {
$ret .= $str;
}
}