dongxiongshi9952 2017-01-18 10:27
浏览 94
已采纳

在方法中使用PHP图像调整大小/裁剪构建的高内存使用率

When cropping and resizing images with PHP functions as imagecreatefromjpeg(), imagecrop(), imagecopyresampled(), and the like, you get notified about high memory usage.

If I implement this crop module into a CMS and say 50 people call the crop function at the same time: will the memory usage be multiplied by 50 and thus overload the server memory resources?

If so what would be a good way to queue requests or prevent the overload?

  • 写回答

1条回答 默认 最新

  • dsuvs66406 2017-01-18 10:47
    关注

    Although this may not be a direct answer to your question, from my experience it is always better to handle image manipulation on another server as you don't want a single user to kill the entire webserver with a few images.

    If you handle your images on a different server and it dies, the worst thing that happens is that the image will return 404, but the webserver itself will keep running just fine.

    In any case, I would definitely recommend using library such as ImageMagick. It is easier to use and I believe you can set memory limit which it cannot exceed.

    The best approach I found for image manipulation so far is AWS Lambda. You can easily write a serverless nodeJS script which downloads your image, performs any modifications to it and uploads it back to your server. Unless you need to process thousands of images every day, you can run it almost for free and it can handle up to 100 simultaneous invocations (it basically starts up to 100 servers at once) so in theory it can be almost 100x faster than if you have to queue your requests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵