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.

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

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀