0

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.

guitarpoet
  • 395
  • 1
  • 5
  • 12
  • It's likely that some system call is failing, or "getting stuck". If this was on my machine, I'd try to investigate it with something like `dtruss`. I think running `dtruss php foo.php` should show the system calls being made, which might provide a clue. – Danack Feb 26 '17 at 14:55
  • @Danack, and it is even weird for me now, I've try to run the php through lldb, and for the first time, it took quite a long time, but have the application run, and then this problem is solved in the console version of PHP. But for the PHP through Apache2 module, it still not working, and I don't know how can I dtruss for that, do you have any suggestions? – guitarpoet Feb 28 '17 at 13:28
  • strace or dtruss can attach to a running process https://8thlight.com/blog/colin-jones/2015/11/06/dtrace-even-better-than-strace-for-osx.html Though possibly just check the file permissions for everything, including temp directories on the server. – Danack Mar 01 '17 at 00:49
  • @Danack I've checked the problem using DTrace, and I found when I try to access the PHP, the system will go into infinite loop of this: select(0x0, 0x0, 0x0, 0x0, 0x7FFF4FDDCB70) = 0 0 wait4(0xFFFFFFFF, 0x7FFF4FDDCB54, 0x3) = 0 0 select(0x0, 0x0, 0x0, 0x0, 0x7FFF4FDDCB70) = 0 0 wait4(0xFFFFFFFF, 0x7FFF4FDDCB54, 0x3) = 0 0 Seems, it is trying to open some file, but kept wait for it. Do you know what can I do from here? – guitarpoet Mar 29 '17 at 09:19
  • Could you post more of the DTrace output somewhere? – Danack Mar 29 '17 at 10:21
  • @Danack The tool I used is dtruss, thee only result I got is like this: select(0x0, 0x0, 0x0, 0x0, 0x7FFF4FDDCB70) = 0 0 wait4(0xFFFFFFFF, 0x7FFF4FDDCB54, 0x3) = 0 0 – guitarpoet Mar 30 '17 at 11:56
  • @Danack, thank you, I've got the problem identified. In fact, when requesting, PHP is busy loading fonts of the system into Memory, and fonts of my system is quite quite large, it will took quite long time to load them, and this exceed the time limit of the PHP execution. Do you have any good ideas for this? – guitarpoet Apr 02 '17 at 05:43

1 Answers1

0

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. :)

guitarpoet
  • 395
  • 1
  • 5
  • 12