0

I'm trying to pull information from Evergage, but based on my console log debugging, the function terminates at the curl_exec function (see comment). debug_to_console("success"); and curl_error both return nothing at all. However, if I debug_to_console("success"); just before curl_exec, it returns properly. When I test run the function, it runs for about 30 seconds and then ends. I originally thought it was a timeout, so I tried removing any time restrictions but it still doesn't seem to be working. Any help would be greatly appreciated. Thanks!

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;

}

Edit: I should mention that I have printed out $requestURI and it is correct. Navigating to it results in the JSON information that I need downloading right away.

  • What does the error log say? – Sam Dufel Jul 23 '14 at 17:27
  • The 30 seconds are most likely from socket_timeout. Are you sure, your server has access to the given host? – SomeoneYouDontKnow Jul 23 '14 at 17:31
  • @SamDufel Well, nothing as far as I can tell. I'm using MAMP to test the function and standard Chrome developer tools to look at the console. Is there is an alternative way to test this that would give me more information? (Sorry for my lack of knowledge, this is my first exposure to PHP.) – user3845511 Jul 23 '14 at 17:31
  • @SomeoneYouDontKnow I'm fairly certain. I can manually insert the URL and the JSON information begins downloading. Wouldn't that confirm that I have access to the host? – user3845511 Jul 23 '14 at 17:32
  • @user3845511 - see http://stackoverflow.com/questions/8641383/how-can-i-get-mamp-to-tell-me-what-went-wrong-with-php-code – Sam Dufel Jul 23 '14 at 17:54
  • @SamDufel Thanks for that reference. The error reads: "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 104442714 bytes) in /Applications/MAMP/htdocs/evergage_final_users.php on line 63". I guess the dataset I'm working with is just too big for this service to handle? – user3845511 Jul 23 '14 at 18:01
  • You should be able to work around it by either increasing the php memory limit or switching from curl to a stream (see the example at http://php.net/manual/en/function.stream-context-create.php) – Sam Dufel Jul 23 '14 at 18:15

0 Answers0