I am trying to use the Khan Academy API but I am running into a small problem. I believe the data being returned by the API call is too large for the variable that is holding the data. I did some Googling and came across a method that sets memory_limit
equal to -1
. I tried this but it did not seem to work for me. Here is the error I am receiving:
Fatal error: Allowed memory size of 125829120 bytes exhausted (tried to allocate 86 bytes) on line 20
Line 20 refers to $array = json_decode($output, true);
Here is my full code:
<?php
ini_set('memory_limit', '-1');
$options = array(
CURLOPT_URL => "http://www.khanacademy.org/api/v1/topictree",
CURLOPT_RETURNTRANSFER => true,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
$array = json_decode($output, true); //Saves the returned JSON object as a multi-dimensional array
foreach ($array as $key => $subarray) {
if ($subarray['readable_id'] == 'financial-crisis-in-thailand-caused-by-speculative-attack') {
echo $subarray['readable_id'];
}
}
?>
try this :
<?php
ini_set('memory_limit', '128M');