dongxiongshi9952 2017-01-18 10:27
浏览 94


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 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办