In PHP, I’m using an in-memory (or rather, temp in-memory) file to load an image from an external URL into a GD resource:
$file = 'php://temp/img';
copy($uri, $file);
$src_img = @imagecreatefromjpeg($file);
However, as I understand it, this file remains in memory, even though I have no use for it after imagecreatefromjpeg().
Is there a way to free memory used by a php://temp wrapper file?
Or atleast signal that the file is no longer used?
When you create a file in php://temp (or php://memory for that matter) the resource only lasts the lifetime of the script. If you open the file using
fopen()to get a resource handle, the lifetime can be shortened usingfclose($resource_handle).In your case, as soon as your script is done executing, the file will no longer be in memory.
In the circumstance where you would like to clear the memory prior to script completion, all you have to do is
fclose()the resource file pointer.On another note, the
/imgyou are using is invalid and is being ignored. The only added data that is recognized is/maxmemory:n.