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

可以加快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.

图片转代码服务由CSDN问答提供 功能建议

我注意到将图像加载到imagick中( $ im = new Imagick($ sFilename); )在php中占用0.6秒的8MB图像。 这对我来说似乎有点慢,所以我尝试了一个测试并使用 file_get_contents 来读取文件。 大约0.005秒。 更好。 有点太好了,我想那里有一些缓存?

但我可以将相同的文件加载到想象中十几次,它总是~0.6秒。 \ n

我可以告诉file_get_contents以某种方式绕过系统缓存,让我更好地了解从硬盘驱动器中检索8MB文件的原始速度吗?

有什么办法可以加速想象力吗? 或者这个操作完全正常是0.6秒?

服务器在RAID 1中有两个7200rpm HP sata驱动器。

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题