PHP Imagick的setFont方法执行时间太长 [英] PHP Imagick's setFont method take too long time to execute

查看:330
本文介绍了PHP Imagick的setFont方法执行时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的环境是这样的:



我的PHP环境使用Imagick, pre> Darwin 16.4.0 Darwin内核版本16.4.0:Thu Dec 22 22:53:21 PST 2016; (NTS)

imagick module version => 3.4.3RC4
imagick classes => Imagick,ImagickDraw,ImagickPixel,ImagickPixelIterator,ImagickKernel
使用ImageMagick编译的Imagick version => ImageMagick 6.9.7-6 Q16 x86_64 2017-02-01 http://www.imagemagick.org
Imagick使用ImageMagick库版本=> ImageMagick 6.9.7-7 Q16 x86_64 2017-02-09 http://www.imagemagick.org

Imagick的setFont方法的执行花费的时间太长(甚至在执行时会得到默认的30秒超时)。



代码就像这样:

 <?php 
$ img = new Imagick();
$ img-> setFont(./ SpicyRice.ttf);
回声完成;

代码 $ img-> setFont(./ SpicyRice。 ttf)将被卡住。



没有错误发生,PHP只是挂在那个方法,超时默认的30秒执行。

有没有人对此有任何想法? 这是我使用的字体文件。


<解决方案



问题是这么简单,但在第一次真的很难识别,我想。

这个问题是我在字体库中安装了很多新的字体,因此,每次当Imagick启动时,它都会尝试获取字体配置和字体配置,尝试读取字体中的每种字体文件夹写字体缓存。

但是,由于PHP有30秒的超时时间,因此在重建字体缓存之前PHP进程将失败。所以,这是无止境的问题,除非我在命令行中运行fc-cache命令并生成字体缓存,那么下一次我调用这个php时,Imagick插件会使用系统的字体缓存来生成所有的字体的信息。

这就解释了为什么在我的命令行中,因为我是系统的用户,系统将为我创建字体缓存只有。

所以,当我使用命令行运行PHP时,它将工作,因为它有正确的字体缓存,但是对于服务器来说,因为它是httpd和运行使用系统的字体缓存,它将无法正常工作。



所以,现在,PHP的imagick工作正常。



再次感谢@达纳克。没有你的帮助,我不会知道这个问题。 :)

I got a very weird problem in my PHP environment using Imagick:

My environment is like this:

Darwin 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

PHP 7.0.16 (cli) (built: Feb 16 2017 22:57:49) ( NTS )

imagick module version => 3.4.3RC4
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 6.9.7-6 Q16 x86_64 2017-02-01 http://www.imagemagick.org
Imagick using ImageMagick library version => ImageMagick 6.9.7-7 Q16 x86_64 2017-02-09 http://www.imagemagick.org

And the method setFont of Imagick will cost too long to execute(and even get the default 30 second timeout in execution).

The code is just like this:

<?php
    $img = new Imagick();
    $img->setFont("./SpicyRice.ttf");
    echo "Done";

And the code $img->setFont("./SpicyRice.ttf") will get stuck.

No error is thrown, PHP just hang at that method, and timeout the default 30 seconds of execution.

Is there anyone have any thoughts about this? This is the font file that I used.

解决方案

With the help by @Danack, I resolve the problem and fix it finally.

The problem is so simple, but is really hard to identify at the first time, I think.

The problem for this is that I installed many new fonts into the font library, and didn't rebuild the font config cache.

So, each time when Imagick initing, it try to get the font config and the font config trying to read every font in my font folder to write the font cache.

But, since PHP has a 30 seconds timeout, so the PHP process will fail before the font cache is rebuilt. So, this is endless problem, unless I run the fc-cache command in the command line, and generate the font cache, then, next time when I call this php, the Imagick plugin will use the system's font cache instead to generate all the informations for the font.

And this explains why this works in my command line, because I'm the user of the system, and the system will create font cache for me only.

So, when I run the PHP using command line, it will work, since it has the right font cache, but for the server, since it is httpd and running using system's font cache, it won't work.

So, for now, PHP's imagick is working like normal.

Thank you again, @Danack. Without your help, I won't know the problem like this. :)

这篇关于PHP Imagick的setFont方法执行时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆