Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 PHP 中,我使用内存中(或者更确切地说,内存中的临时文件)将图像从外部 URL 加载到 GD 资源中:
$file = 'php://temp/img'; copy($uri, $file); $src_img = @imagecreatefromjpeg($file);
但是,据我了解,该文件仍保留在内存中,即使在imagecreatefromjpeg().
imagecreatefromjpeg()
有没有办法释放 php://temp 包装文件使用的内存?
或者至少表明该文件不再使用?
当您在php://temp(或 php://memory )中创建文件时,资源仅持续脚本的生命周期。如果您使用打开文件fopen()来获取资源句柄,则可以使用fclose($resource_handle).
fopen()
fclose($resource_handle)
在您的情况下,一旦您的脚本执行完毕,该文件将不再在内存中。
如果您想在脚本完成之前清除内存,您所要做的就是fclose()资源文件指针。
fclose()
另一方面,/img您正在使用的 无效并且被忽略。唯一可以识别的添加数据是/maxmemory:n.
/img
/maxmemory:n