简体   繁体   English

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

[英]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. 我注意到在php $im = new Imagick($sFilename);图像加载到imagick( $im = new Imagick($sFilename); )中需要花费0.8秒的时间来获取8MB图像。 This seems a bit slow to me, so I tried a test and read the file in using file_get_contents instead. 这对我来说似乎有点慢,所以我尝试了一个测试,而是使用file_get_contents读取了文件。 About 0.005 seconds. 大约0.005秒。 Better. 更好。 A bit too good tbh, I guess there's some caching going on there? tbh有点太好了,我想那儿有些缓存了吗?

But I can load the same file a dozen times into imagick and it's always ~0.6 seconds. 但是我可以将同一个文件加载到imagick中十次,并且总是〜0.6秒。

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? 我可以告诉file_get_contents以某种方式绕过系统缓存,以便更好地了解可以从硬盘驱动器检索8MB文件的原始速度吗?

Is there anything that can be done to speed up imagick? 有什么可以做的来加快imagick的速度吗? Or is 0.6 seconds for this operation completely normal? 还是0.6秒的操作时间完全正常?

The server has two 7200rpm HP sata drives in RAID 1. 该服务器在RAID 1中有两个7200rpm HP sata驱动器。

Thanks. 谢谢。

Is there anything that can be done to speed up imagick? 有什么可以做的来加快imagick的速度吗?

Buy a faster CPU 购买更快的CPU

Or is 0.6 seconds for this operation completely normal? 还是0.6秒的操作时间完全正常?

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. file_get_contents只是从磁盘上读取文件中的字节。 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. 从JPG创建图像意味着计算机必须从磁盘上读取字节,然后将它们从压缩数据中解码为实际图像数据。

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. 是的,这比HTTP请求进行处理的合理时间长。 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. 这就是为什么不在网络服务器中运行Imagick是一个好主意,而是将其作为后台任务运行的另一个原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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