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 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口