1

I have image creating php script . It works fine when i access it from the browser . But when it is called from a shell script it shows the following error .

PHP Fatal error: Call to undefined function imagecreate()

1
  • 2
    cli php can/will use different .ini files than the sapi(browser) version. check that GD is being loaded into your cli php setup. Commented Dec 13, 2012 at 15:52

2 Answers 2

1

PHP CLI probably doesn't use the same configuration file than the browser one. So it doesn't load the GD library.

You could either force him to use the same .ini file :

php -c /directory/php.ini phpscript.php

Or add the following line in your PHP CLI configuration file :

; Enable gd extension module
extension=gd.so
Sign up to request clarification or add additional context in comments.

Comments

1

You can check if the gd is loaded and try to load it dynamically

<?php
if (!extension_loaded('gd')) {
    if (!dl('gd.so')) {
        echo "GD cannot be loaded";
        exit;
    }
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.