PHP脚本在一台服务器上运行Cronjob但在类似服务器上运行

时间:2014-11-05 13:54:47

标签: php mysql

我通过一台服务器上的cronjob(VPS WHM)运行此脚本,并将所有内容复制到具有相同类型的VPS和WHM的另一台主机上。此脚本未在新服务器上运行,或者未发送电子邮件。我试图与提供商进行故障排除,他们不知所措。我的问题是什么设置可能会导致这样的问题?我似乎搞砸了服务器上的每个设置几乎没有结果。任何有助于跟踪此信息的信息,请告知我,我将编辑问题。如果你有猜测也会有所帮助,我只是在寻找新问题。

更多信息:

Apache版本2.2.27 PHP版本5.4.31 MySQL版本5.5.40-cll

日志中没有错误

Cron是:10 4 * * * php /home/xxxxx/public_html/alert.php

我也试过:10 4 * * * /home/xxxxx/public_html/alert.php

    #!/usr/bin/php
<?php

$db_host = "localhost"; 
$db_username = "xxxx"; 
$db_pass = "xxxx"; 
$db_name = "xxxxxx"; 
mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error()); 
mysql_select_db("$db_name") or die ("no database");

$headers = "Bcc: xxxxx@xxxx.com";

$tierasql =  "SELECT date,phonenumber,email, SUM(dataplan) AS currentplantiera, SUM(datamb) AS value_sumtiera FROM maindata2 WHERE dataplan BETWEEN 2 and 50 and dataplan != '20' GROUP BY email";


$resulttiera = mysql_query($tierasql);
while ($rowtiera = mysql_fetch_assoc($resulttiera)){
if ($resulttiera){
  $rowtiera = mysql_fetch_assoc($resulttiera);
  $plantiera = $rowtiera['currentplantiera'] ;
  $date = $rowtiera['date'] ;
  $inventorytiera = ROUND ($rowtiera["value_sumtiera"],2) ;
  $recipienttiera = $rowtiera['email'];
  if ($inventorytiera > (.75 * $plantiera)){
    $msgtiera = "Xxxxxxxxx Data Usage Alert:

This alert is being provided to you because your lines in Tier A have exceeded 75% of your Xxxxxxxxx Service Plan. 

As of $date, your current data usage is $inventorytiera MB and you have a data allotment of $plantiera MB of shared data. 

Please note that you may experience overage charges if your total data usage exceeds the net total usage of all data in the same sharing tier until your usage is reset on your next billing cycle.  

One upward rate plan adjustment is allowed per billing cycle, please visit http://xxxxxxxxx.com/rate-plan-change for more details.

Please refer to Xxxxxxxxx.com/data to review your data usage.";
    mail($recipienttiera,"xxxxx@xxxx.com", "Xxxxxxxxx Data Usage Alert", $msgtiera, $headers);
  }
}
else {
  $msg = "An error occurred: " . mysql_error();
  mail($recipienttiera,"xxxxx@xxxx.com", "Alert from Xxxxxxxxx error", $msgtiera, $headers);

}
}

$tierbsql =  "SELECT date,phonenumber,email, SUM(dataplan) AS currentplantierb, SUM(datamb) AS value_sumtierb FROM maindata2 WHERE dataplan BETWEEN 500 and 8000 GROUP BY email";


$resulttierb = mysql_query($tierbsql);
while ($rowtierb = mysql_fetch_assoc($resulttierb)){
if ($resulttierb){
  $rowtierb = mysql_fetch_assoc($resulttierb);
  $plantierb = $rowtierb['currentplantierb'] ;
  $date = $rowtierb['date'] ;
  $inventorytierb = ROUND ($rowtierb["value_sumtierb"],2) ;
  $recipienttierb = $rowtierb['email'];
  if ($inventorytierb > (.75 * $plantierb)){
    $msgtierb = "Xxxxxxxxx Data Usage Alert:

This alert is being provided to you because your lines in Tier B have exceeded 75% of your Xxxxxxxxx Service Plan. 

As of $date, your current data usage is $inventorytierb MB and you have a data allotment of $plantierb MB of shared data.  

Please note that you may experience overage charges if your total data usage exceeds the net total usage of all data in the same sharing tier until your usage is reset on your next billing cycle.  

One upward rate plan adjustment is allowed per billing cycle, please visit http://xxxxxxxxx.com/rate-plan-change for more details.

Please refer to Xxxxxxxxx.com/data to review your data usage.";
    mail($recipienttierb,"xxxxx@xxxx.com", "Xxxxxxxxx Data Usage Alert", $msgtierb, $headers);
  }
}
else {
  $msg = "An error occurred: " . mysql_error();
  mail($recipienttierb,"xxxxx@xxxx.com", "Alert from Xxxxxxxxx error", $msg, $headers);

}
}

$tiercsql =  "SELECT date,phonenumber,email, SUM(dataplan) AS currentplantierc, SUM(datamb) AS value_sumtierc FROM maindata2 WHERE dataplan BETWEEN 10000 and 100000 GROUP BY email";


$resulttierc = mysql_query($tiercsql);
while ($rowtierc = mysql_fetch_assoc($resulttierc)){
if ($resulttierc){
  $rowtierc = mysql_fetch_assoc($resulttierc);
  $plantierc = $rowtierc['currentplantierc'] ;
  $date = $rowtierc['date'] ;
  $inventorytierc = ROUND ($rowtierc["value_sumtierc"],2) ;
  $recipienttierc = $rowtierc['email'];
  if ($inventorytierc > (.75 * $plantierc)){
    $msgtierc = "Xxxxxxxxx Data Usage Alert:

This alert is being provided to you because your lines in Tier B have exceeded 75% of your Xxxxxxxxx Service Plan. 

As of $date, your current data usage is $inventorytierc MB and you have a data allotment of $plantierc MB of shared data.  

Please note that you may experience overage charges if your total data usage exceeds the net total usage of all data in the same sharing tier until your usage is reset on your next billing cycle.  

One upward rate plan adjustment is allowed per billing cycle, please visit http://xxxxxxxxx.com/rate-plan-change for more details.

Please refer to Xxxxxxxxx.com/data to review your data usage.";
    mail($recipienttierc,"xxxxx@xxxx.com", "Xxxxxxxxx Data Usage Alert", $msgtierc, $headers);
  }
}
else {
  $msg = "An error occurred: " . mysql_error();
  mail($recipienttierc,"xxxxx@xxxx.com", "Alert from Xxxxxxxxx error", $msg, $headers);

}
}


$sql =  "SELECT date,phonenumber,email, dataplan AS currentplan, SUM(datamb) AS value_sum FROM maindata2 GROUP BY phonenumber, dataplan";


$result = mysql_query($sql);
if ($result) {
    while ($row = mysql_fetch_assoc($result)){
        $plan = $row['currentplan'] ;
            $date = $row['date'] ;
            $inventory = ROUND ($row["value_sum"],2) ;
            $recipient = $row['email'];
            $line = $row['phonenumber'];
            if ($inventory > (.75 * $plan)) {
    $msg = "Xxxxxxxxx Single Line Usage Alert:

This alert is being provided to you because your line $line has exceeded 75% of it's Xxxxxxxxx Service Plan.   

As of $date, your current data usage is $inventory MB of your $plan MB data plan. 

Please note that you may experience overage charges if your total data usage exceeds the net total usage of all data in the same sharing tier until your usage is reset on your next billing cycle.  

One upward rate plan adjustment is allowed per billing cycle, please visit http://xxxxxxxxx.com/rate-plan-change for more details.

Please refer to Xxxxxxxxx.com/data to review your data usage.";
    mail($recipient,"xxxxx@xxxx.com", "Alert from Xxxxxxxxx", $msg, $headers);
  }
}
}
else {
  $msg = "An error occurred: " . mysql_error();
  mail($recipient,"xxxxx@xxxx.com", "Alert from Xxxxxxxxx error", $msg, $headers);

}




        ?>

1 个答案:

答案 0 :(得分:0)

您是否检查过新服务器上的php-cli错误日志?运行时可能会出错。如果日志中没有错误,则可能根本不运行。尝试使用php命令手动触发作业,看它是否成功,然后将其添加到cron并检查错误日志。