我被困在一个 cron 脚本中,需要你的帮助。
我的网站托管在 1and1 服务器上。我使用类函数结构在 php 中编写了一个 cron 脚本。
实际上有两个脚本。它们是:1)init.php 2)job.php
在 init.php 中,我编写了必要的类和函数。在 job.php 脚本中,我在顶部和下方包含了 init.php,为此我编写了其他功能(数据库查询和发送电子邮件)。
如果我直接使用浏览器(http://www.abc.com/job.php)执行脚本,脚本执行得很好。我收到电子邮件。但是,在使用 shell 将此脚本设置为 cron 任务后,我没有得到任何响应。我也不知道如何检查 cron 的错误日志。
php文件的示例结构如下:
初始化.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;
工作.php:
要求('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'];
}
.
.
.
.
}
请帮我执行这个脚本。
** cron 作业是使用 SSH 访问设置的。
下面提到的命令已用于设置 cron 脚本。
- /usr/bin/php /a/b/htdocs/scripts/job.php
为了检查我的 shell 命令和配置是否执行,我还添加了一个测试脚本。测试脚本正确执行。**
在对功能一一分析后,我发现下面的代码没有执行。变量已正确初始化,但未创建“SoapClient”对象。请注意,SoapClient 类不是我定义的,而是 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();
}
请建议我需要的。