可以在 php/imagick 中加快图像加载速度
Possible to speed up image loading in php/imagick
我注意到在 php 中将图像加载到 imagick ($im = new Imagick($sFilename);
) 中对于 8MB 图像需要 0.6 秒。这对我来说似乎有点慢,所以我尝试了一个测试并改为使用 file_get_contents
读取文件。大约 0.005 秒。更好的。有点太好了,我想那里正在进行一些缓存?
但是我可以将同一个文件加载到 imagick 中十几次,而且总是大约 0.6 秒。
我可以告诉 file_get_contents 以某种方式绕过系统缓存,让我更好地了解从我的硬盘驱动器检索 8MB 文件的原始速度吗?
有什么办法可以加快 imagick 的速度吗?还是这个操作0.6秒完全正常?
服务器在 RAID 1 中有两个 7200rpm HP sata 驱动器。
谢谢。
Is there anything that can be done to speed up imagick?
买一个更快CPU
Or is 0.6 seconds for this operation completely normal?
是的。
This seems a bit slow to me
but it seems a long time for that.
I guess there's some caching going on there?
您只是在猜测某些东西应该更快.....并且您将其与完全不同的操作进行比较。 file_get_contents 只是从磁盘中读取文件中的字节。从 JPG 创建图像意味着计算机必须从磁盘读取字节,然后从压缩数据中将其解码为实际图像数据。
如果您想查看在压缩过程中需要完成多少工作,可以通过以未压缩格式写出图像来轻松查看,例如
$imagick = new Imagick("./testImage.jpg");
$imagick->setImageFormat('BMP');
$imagick->writeImage("./output.bmp");
是的,这比处理 HTTP 请求的合理时间长。这就是为什么 运行 在网络服务器中使用 Imagick 不是一个好主意,而是 运行 将其作为后台任务的另一个原因。
我注意到在 php 中将图像加载到 imagick ($im = new Imagick($sFilename);
) 中对于 8MB 图像需要 0.6 秒。这对我来说似乎有点慢,所以我尝试了一个测试并改为使用 file_get_contents
读取文件。大约 0.005 秒。更好的。有点太好了,我想那里正在进行一些缓存?
但是我可以将同一个文件加载到 imagick 中十几次,而且总是大约 0.6 秒。
我可以告诉 file_get_contents 以某种方式绕过系统缓存,让我更好地了解从我的硬盘驱动器检索 8MB 文件的原始速度吗?
有什么办法可以加快 imagick 的速度吗?还是这个操作0.6秒完全正常?
服务器在 RAID 1 中有两个 7200rpm HP sata 驱动器。
谢谢。
Is there anything that can be done to speed up imagick?
买一个更快CPU
Or is 0.6 seconds for this operation completely normal?
是的。
This seems a bit slow to me
but it seems a long time for that.
I guess there's some caching going on there?
您只是在猜测某些东西应该更快.....并且您将其与完全不同的操作进行比较。 file_get_contents 只是从磁盘中读取文件中的字节。从 JPG 创建图像意味着计算机必须从磁盘读取字节,然后从压缩数据中将其解码为实际图像数据。
如果您想查看在压缩过程中需要完成多少工作,可以通过以未压缩格式写出图像来轻松查看,例如
$imagick = new Imagick("./testImage.jpg");
$imagick->setImageFormat('BMP');
$imagick->writeImage("./output.bmp");
是的,这比处理 HTTP 请求的合理时间长。这就是为什么 运行 在网络服务器中使用 Imagick 不是一个好主意,而是 运行 将其作为后台任务的另一个原因。