Spaces:
Running
Running
File size: 1,778 Bytes
ea02d49 060a0b2 ea02d49 060a0b2 ea02d49 | 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 53 54 55 56 57 58 | <?php
function httpGet($url, $timeout = 15) {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CONNECTTIMEOUT => $timeout,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_USERAGENT => 'BuddhaWord/1.0',
CURLOPT_HTTPGET => true,
]);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($result !== false && $httpCode >= 200 && $httpCode < 300) {
return $result;
}
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => $timeout * 2,
CURLOPT_CONNECTTIMEOUT => $timeout,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'BuddhaWord/1.0',
CURLOPT_HTTPGET => true,
]);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($result !== false && $httpCode >= 200 && $httpCode < 300) {
return $result;
}
}
$context = stream_context_create([
'http' => [
'method' => 'GET',
'timeout' => $timeout,
'user_agent' => 'BuddhaWord/1.0',
],
'ssl' => ['verify_peer' => false, 'verify_peer_name' => false],
]);
return @file_get_contents($url, false, $context);
}
|