doubei3312 2014-08-27 19:46
浏览 51
已采纳

通过cron运行php脚本。 如何让它报告失败?

I have a PHP script that I want to run on a cronjob. I am assuming if PHP fails due to a fatal error it will terminate the script which reports to cron of an error, however how do I force a failure reply that will instruct cron of an issue?

I will have some database calls and I want cron to report back an error (which fires off an email) if the database queries fail.

  • 写回答

1条回答 默认 最新

  • drl959975 2014-08-27 20:12
    关注

    Here is what I do:

    $query1 = "some query";
    $results = mysql_query($query1);
    $query1Error = mysql_error();
    
    $query2 = "a different query";
    $results = mysql_query($query2);
    $query2Error = mysql_error();
    
    if(!empty($query1Error) || !empty($query2Error) ) {
            $message = "An error occured updating the funnel. The details are below:"."
    
    ";
            $message = print_r($_POST,TRUE);
            $message .= "
    
    Query 1: ".$query1;
            $message.="
    
     Query 1 Error: ".$query1Error; 
            $message .= "
    
    Query 2: ".$query2;
            $message.="
    
     Query 2 Error: ".$query2Error; 
            mail("someone@somewhere.com","Error updating funnel ".__FILE__." ",$message);  
       }
    

    Of course, when i get around to it, I will replace the depreciated MySQL stuff.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号