douyue9704 2015-12-03 15:27
浏览 586
已采纳

可以加快php / imagick中的图像加载速度

I've noticed that loading an image into imagick ($im = new Imagick($sFilename);) in php is taking 0.6 seconds for an 8MB image. This seems a bit slow to me, so I tried a test and read the file in using file_get_contents instead. About 0.005 seconds. Better. A bit too good tbh, I guess there's some caching going on there?

But I can load the same file a dozen times into imagick and it's always ~0.6 seconds.

Can I tell file_get_contents to bypass the system cache somehow, to give me a better idea of the raw speed with which an 8MB file can be retrieved from my hard drives?

Is there anything that can be done to speed up imagick? Or is 0.6 seconds for this operation completely normal?

The server has two 7200rpm HP sata drives in RAID 1.

Thanks.

  • 写回答

1条回答 默认 最新

  • duandou8457 2015-12-03 17:32
    关注

    Is there anything that can be done to speed up imagick?

    Buy a faster CPU

    Or is 0.6 seconds for this operation completely normal?

    Yes.

    This seems a bit slow to me

    but it seems a long time for that.

    I guess there's some caching going on there?

    You're just guessing that something should be faster.....and you'r comparing it to a completely different operation. file_get_contents just reads the bytes in the file off the disk. Creating an image from a JPG means the computer has to read the bytes off the disk, and then decode them from the compressed data to be the actual image data.

    If you want to see how much work has to be done during the compression, you can easily see this by writing the image out in an uncompressed format e.g.

    $imagick = new Imagick("./testImage.jpg");
    $imagick->setImageFormat('BMP');
    $imagick->writeImage("./output.bmp");
    

    And yes, this is longer than is reasonable for a HTTP request to take processing. Which is just another reason for why not running Imagick in a webserver is a good idea, but to instead run it as a background task.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog