Using Imagick in command line php
Using Imagick in command line php
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
Try using the full path - something like:
Code: Select all
php /home/user/www/folder/script.php
Re: Using Imagick in command line php
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Using Imagick in command line php
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.
________________
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
How about trying a test using Imagemagick with exec() instead of Imagick?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Using Imagick in command line php
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
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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/