0

I've got a basic script that I want to run from a cronjob:

require("/opt/lampp/htdocs/cronjobs/aws-sdk-for-php/sdk.class.php");

$amazonSes = new AmazonSES(array( "key" => $AWS_KEY, "secret" => $AWS_SECRET_KEY, "certificate_authority" => $CA ));


$response = $amazonSes->send_raw_email(array(
                'Data'=> base64_encode($message)),
                     array('Source'=>$src, 'Destinations'=> $dest));

The above works perfectly when I load the .php from the browser. But from the command line or conjob it returns this fatal error:

Fatal error: Call to undefined function curl_init() in /opt/lampp/htdocs/cronjobs/aws-sdk-for-php/lib/requestcore/requestcore.class.php on line 615

Any ideas?

1
  • command line php does not have curl in it Commented Dec 1, 2013 at 19:57

2 Answers 2

1

Your webserver (apache presumably) is either using a different copy of PHP than the one you use when calling it from the commandline (called CLI), or it is using a different configuration file.

Regardless, you can use phpinfo() and call that on your browser to see the path to your PHP copy which is being used. On the commandline you can call php -ini and look for the path to your PHP copy.

The error you get is because your CLI version of PHP is configured to not incorporate the curl library. Therefore use the commandline to get the loaded configuration file (INI) and use a text editor to edit that file and enable curl.

Sign up to request clarification or add additional context in comments.

Comments

0

Your CLI (command line interface) PHP is using a different PHP.INI. When calling PHP from command line, use arguments to make PHP use the same PHP.INI. (see php --help to see the available arguments.)

Or ... configure the alternative PHP.INI that is used by the CLI PHP. (Try opening a php file from CLI that only contains the following code: <?php phpinfo(); ?>. It will tell you which PHP.INI is exactly being used.

5 Comments

Ahh.. how do i make CLI use the same settings?
use <?php phpinfo(); ?> on both CLI and webserver, and see which PHP.INI's they are using. Make CLI point to the same PHP.INI as the webserver is using.
Ahh i see that my CLI is using /etc/php5/cli and my browser is using /opt/lampp/etc/php.ini how can i change the CLI to use the same .ini as my browser? What file do i edit for that?
Instead of using the same file, you could just edit the other configuration file in order to incorporate curl. Makes more sense since you might want other configuration options to remain different (between web and CLI)
@Alosyius you indeed better just use different files, as I also had described in my answer. What you could do is start with a copy of the contents of /opt/lampp/etc/php.ini and put it in /etc/php5/cli. Then you can change the second files and put only stuff in there that should apply for cli. (For example, the max run time of a php script is 30 sec. by default. On CLI you might want to have unlimited time.)

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.