如何使用Imagick运行PHP的cron作业?

如何使用Imagick运行PHP的cron作业?

问题描述:

I have a php script that uses imagick to get image colors among other things.

php /home/username/public_html/cron.php

I would get this error on the scheduled run

[30-Apr-2013 00:00:02] PHP Fatal error: Class 'Imagick' not found in /home/username/public_html/cron.php on line 113

A sample of the php code:

try {
      $image = new Imagick($filename);
      $image->scaleImage(1,1);
            $pixel = $image->getImagePixelColor(1, 1); 
            $color = $pixel->getColor(); 
            $image_r = $color['r'];
            $image_g = $color['g'];
            $image_b = $color['b'];

            $image->destroy();


    } catch (ImagickException $e) {
        // something went wrong, handle the problem
            $image_r = 0;
            $image_g = 0;
            $image_b = 0;


    }

Do I need set up some environmental variable so it knows where to look for imagick? It works fine if I invoke the php script from the browser. Hopefully I can move this script out of the public_html when I have it working so I don't get a third party calling it.

thanks.

Assuming it works in non cron environment, I notice your script is in the web root. how about using wget instead:

wget http://localhost/cron.php

You need to set path of your imagemagick something like this used to work for me

imagemagickpath = /usr/bin/imagemagick

in some config file

and then use that imagemagickpath