我试图从Evergage中提取信息,但根据我的控制台日志调试,该函数终止于curl_exec
函数(请参阅注释)。 debug_to_console("success");
和curl_error
都没有返回任何内容。但是,如果我在debug_to_console("success");
之前curl_exec
,则会正确返回。当我测试运行该功能时,它运行大约30秒然后结束。我原本以为这是暂停,所以我尝试删除任何时间限制,但它似乎仍然没有工作。任何帮助将不胜感激。谢谢!
function RetrieveData($account, $dataset, $kind, $apiToken)
{
$port = "";
if ($account === "localtest") {
$port = ":8443";
}
$requestURI = "https://" . $account . ".evergage.com" . $port . "/api/dataset/" . $dataset . "/" . $kind . ".json?_at=" . $apiToken;
debug_to_console("request URL: " . $requestURI);
$session = curl_init();
curl_setopt($session, CURLOPT_FAILONERROR, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($session, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($session, CURLOPT_URL, $requestURI);
// EVERYTHING RUNS FINE UP TO THIS POINT
set_time_limit(0);
$response = curl_exec($session);
debug_to_console("success");
echo 'Curl error: ' . curl_error($session);
$info = curl_getinfo($session);
$responseCode = $info["http_code"];
if ($responseCode >= 300) {
print("Error loading data: " . $responseCode . "<br/>");
print($response);
} else {
$body = substr($response, $info['header_size']);
$decoded_result = json_decode($body, true);
}
curl_close($session);
return $decoded_result;
}
编辑:我应该提一下,我已打印出$ requestURI,这是正确的。导航到它会产生我需要立即下载的JSON信息。