first WIP implementation
This commit is contained in:
52
functions.php
Normal file
52
functions.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
function abort($msg="Unknown")
|
||||
{
|
||||
header("403 Forbidden");
|
||||
$response = array(
|
||||
"success" => false,
|
||||
"message" => $msg
|
||||
);
|
||||
echo json_encode($response);
|
||||
print("\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
function exec_curl_request($handle)
|
||||
{
|
||||
$response = curl_exec($handle);
|
||||
|
||||
if ($response === false) {
|
||||
$errno = curl_errno($handle);
|
||||
$error = curl_error($handle);
|
||||
error_log("Curl returned error $errno: $error\n");
|
||||
curl_close($handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
|
||||
curl_close($handle);
|
||||
|
||||
if ($http_code >= 500) {
|
||||
// do not want to DDOS server if something goes wrong
|
||||
sleep(10);
|
||||
return false;
|
||||
} else if ($http_code != 200) {
|
||||
$response = json_decode($response, true);
|
||||
error_log("Request has failed with error {$response['error']}\n");
|
||||
if ($http_code == 401) {
|
||||
throw new Exception('Invalid access token provided');
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
$response = json_decode($response, true);
|
||||
if (isset($response["event_id"])) {
|
||||
$response = true;
|
||||
} else {
|
||||
$response = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user