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.

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

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化