tags:

views:

168

answers:

2

I have a php script, and need to run it everyday. This script has a soapclient, and it works fine if I run it as a script using browser directly. However, some fatal errors if I set it as a cron job.

The script is very simple as "crontest.php"

<?php 

$mage_url = 'http://******.com/api/?wsdl'; 
$mage_user = '*****'; 
$mage_api_key = '******';

$soap = new SoapClient( $mage_url ); 
echo "success";

exit;
?>

And the cronjob I set is

0 8 * * * /usr/bin/php /home/duan/public_html/scripts/crontest.php

The error it gives is

Fatal error: Class 'SoapClient' not found in /home/duan/public_html/scripts/crontest.php

It works fine if I remove line

$soap = new SoapClient( $mage_url );

Anyone can help?

A: 

Instead of running your script by calling php directly, try using lynx to get the server to load the page through an http request:

/usr/bin/lynx -source http://example.com/cron.php

This should cause the script to be run in the same manner as when you view it yourself through your web browser. Test it out on the command line first, and then for your cron job you can just divert the output to /dev/null or a log as appropriate:

/usr/bin/lynx -source http://example.com/cron.php > /dev/null 2>&1

GApple
A: 

You probably need to include the file nusoap.php or load the php library. It is only included after version 5.0.1, but the server might not use it (especially if you use nusoap, which has the same class name).

You should search the website code and look for the inclusion of nusoap.php or a command like dl('SoapClient') (dl loads a php library).

If its not nusoap, you could try the command php -m and see if SoapClient is there. If not try php -v.

OIS