简体   繁体   中英

Possible to speed up image loading in 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.

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 eg

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM