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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记