I am stuck in a cron script and need your help.
My site is hosted on 1and1 server. I have written a cron script in php using class function structure.
There are two scripts actually. Those are: 1) init.php 2) job.php
In init.php i have written the necessary class and functions. In job.php script, i have included the init.php at the top and below to this i have written other functionality (database query and sending of emails).
If i execute the script directly using the browser (http://www.abc.com/job.php), the script is executing fine. I am getting emails. But, i am not getting any response after setting this script as a cron task using shell. I have no idea how to check the error log of the cron as well.
Sample structure of the php file is given below:
init.php:
define('DB_SERVER','***********');
define('DB_USERNAME','*******');
define('DB_PASSWARD','******');
define('DB_DATABASE','*******');
class information{
public function __construct(){
$connection = mysql_connect(DB_SERVER,DB_USERNAME,DB_PASSWARD) or die ('connection error'.mysql_error());
mysql_select_db(DB_DATABASE,$connection) or die('database error'.mysql_error());
}
public function configuration(){
$sql = "SELECT * FROM config order by id";
$exe = mysql_query($sql);
$site_config = array();
while($res = mysql_fetch_array($exe)){
$site_config[$res['name']]=$res['value'];
}
return $site_config;
}
}
$obj = new information;
job.php:
require('init.php');
class Achdirect_cmi
{
private $ID;
private $AID;
private $Key;
public $site_config;
public function __construct()
{
global $obj;
$this->site_config = $obj->configuration();
$this->ID = $this->site_config['id'];
$this->AID = $this->site_config['A_id'];
$this->Key = $this->site_config['key'];
}
.
.
.
.
}
Please help me to execute this script.
**The cron job is setup using SSH access.
Below mentioned command has been used to to set the cron script.
- /usr/bin/php /a/b/htdocs/scripts/job.php
To check whether my shell command and configuration executes or not, i have added a test script as well. The test script executed properly.**
After analyzing the functionality one by one, i have found that the below code is not executing. Variables have been initialized properly but not creating the object of "SoapClient". Please note, the class SoapClient is not defined by me, but its a core functionality of php5.
try{
$client = new SoapClient($url, array("location" => $location));
$params = array("ticket" => $auth_array, "MerchantID" => $MerchantID, "TransactionID" => $trace_number );
$response = $client->getTransaction($params);
}
catch (Exception $e){
echo $e->getMessage();
}
Please suggest me the needful.