i'm experiencing some fatal errors when using CURL to retrieve remote images.
Error Message: PHP Fatal error: Out of memory (allocated 786432) (tried to allocate 266241 bytes)
I have a function designed to retrieve the remote image and return it to a variable:
function download_file($file, $ref)
{
$curl_obj = curl_init();
curl_setopt($curl_obj, CURLOPT_URL, $file);
curl_setopt($curl_obj, CURLOPT_HEADER, 0);
curl_setopt($curl_obj, CURLOPT_REFERER, $ref);
curl_setopt($curl_obj, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_obj, CURLOPT_MAXREDIRS, 3);
curl_setopt($curl_obj, CURLOPT_FOLLOWLOCATION, TRUE); //followlocation cannot be used when safe_mode/open_basedir are on
curl_setopt($curl_obj, CURLOPT_SSL_VERIFYPEER, FALSE);
if(!$downloaded_binary = curl_exec($curl_obj)){
$downloaded_binary = false; // downloading failed, return false
}
curl_close($curl_obj);
unset($curl_obj);
return $downloaded_binary;
}
The failure occurs when curl_exec is called.
Background
The application itself exports image (TIFF) data from a proprietary document management system, converts the associated images into a single PDF document and writes the files out to a logical structure.
The failure does not make sense to me, since each curl instance should be a new handle.
Any help or direction on this would be greatly appreciated!
EDIT
I believe I found the resolution to the issue, by adding the following lines: IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, 3072); IMagick::setResourceLimit(imagick::RESOURCETYPE_MAP, 3072);
Found in this post: PHP Imagick memory leak