I need to use cURL with PHP to access a big file inside a Cloud storage. The storage URL change according to request. The PHP script is using a library to grant access using cURL and return the file.
But, HTTP request is throwing a 500 status because PHP is failing with the error:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133700011 bytes)
So, How can I properly redirect the requests? The field Location:
is not working too because it misses the extra parameter inside the HTTP header.
Here is the script:
function fetch($url, $cookie=null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Any hints?