Page 1 of 1

Using Imagick in command line php

Posted: 2010-07-08T13:21:17-07:00
by adamlangsner
I am writing a php script to use in my cron, and whenever i run the script manually, "php script.php" it says that the Imagick class cannot be found, but if I call the script from my browser it works fine. Any help is most appreciated

Re: Using Imagick in command line php

Posted: 2010-07-08T14:23:41-07:00
by Bonzo
Try using the full path - something like:

Code: Select all

php /home/user/www/folder/script.php

Re: Using Imagick in command line php

Posted: 2010-07-08T19:34:42-07:00
by adamlangsner
That doesn't work. If I was to have a cronjob that used curl to call the script do you think that would work. Kind of a messy workaround but I've gotta get it working.

Re: Using Imagick in command line php

Posted: 2010-07-08T19:59:05-07:00
by fmw42
Have you included the full path to convert or any other IM commands in your php script. PHP does not always know where IM lives.

________________

Sorry, I thought you were using PHP exec and not Imagick. Don't know Imagick well enough to help. Sounds like an Imagick installation problem.

Re: Using Imagick in command line php

Posted: 2010-07-09T12:37:49-07:00
by Bonzo
How about trying a test using Imagemagick with exec() instead of Imagick?

Re: Using Imagick in command line php

Posted: 2010-07-10T17:57:42-07:00
by anthony
Running programs from cron is much the same as running them from a web server. The program is being run in a different environment from the 'normal' interactive command line interface.

As such like for web launched PHP, cron launched PHP has the same problems. The environment is not guaranteed. You may not be in the right directory, you may not have the right (or only a minimal) environment variables, and more importantly the command PATH and library LD_LIBRARY_PATH may not include the right locations.

PHP makes this hard by typically disallowing user PHP script form setting environment variables in the script itself. This is for security reasons, as these should be set in the PHP.ini file, which requires System Programmer Privileges. :-(

One solution for BOTH is as mentioned, fully specify all command and image paths. Whether library paths is needed depends on your installed version of IM (installed or private build) and the delegates programs and libraries it uses, typically it is not needed.

Another is to wrapper the "convert" command (or whatever command you are launching form PHP, with something that will define the environment fully (current directory, PATH, and any other environment).


Getting and Logging the Standard Error from PHP scripts is probably more imporant than anything else, as it will generally tell you want is wrong. See my notes on PHP logging...
http://www.cit.griffith.edu.au/~anthony ... /php.hints