简体   繁体   English

PHP中的Cron作业错误

[英]Cron job error in php

<!DOCTYPE html>
<html>
<head>
<title>MY Database</title>
</head>
<body>
<?php
        $dbcon=mysql_connect("localhost","santu_dbuser","santulan@123") or die("mysql connection error".mysql_error());
        mysql_select_db("santu_db",$dbcon) or die("mysql database error".mysql_error());
        $qry="SELECT DISTINCT CaseId,eemp_id, MAX(FeedbackDate) from session_feedback_master WHERE added_by like 'USER' GROUP BY CaseId";
        $result=mysql_query($qry) or die("mysql query error".mysql_error());

ini_set("SMTP","localhost");

ini_set("smtp_port","25");

ini_set('sendmail_from', 'no.reply@santulan.co.in');

        $num=mysql_num_rows($result);

        if($num>0)
        {       
?>
        <table border="1px">    
        <tr>
            <td>Case Id</td>
               <td>Feedback Date</td>
            <td>Emp Id</td>
            <td>Email</td>  
        </tr>
    <?php
        while($row=mysql_fetch_assoc($result))
        {
        echo "<tr>";
       echo "<td>".$row["CaseId"]."</td>";
         echo "<td>".$row["MAX(FeedbackDate)"]."</td>";
             echo "<td>".$row["eemp_id"]."</td>";         
             echo "</tr>";
        <!--- for calculation--->

        $mydate=new DateTime($row["MAX(FeedbackDate)"]);
        $eemp_id=$row["eemp_id"];               
        echo $eemp_id;  
        $now=new DateTime('today');
        echo "Diffrence in days";
        echo $datediff =  $now->diff($mydate)->d;
        //echo "<br>";      
        if($datediff>10)
        {
        echo "we are checking"; 
        $eemp_id=$row["eemp_id"];       
            $qry="SELECT email FROM  end_employee_master where id=".$eemp_id ;
            $result1=mysql_query($qry) or die("mysql query error".mysql_error());
            $num=mysql_num_rows($result1);
            echo $num;
            if($result1)
            {

                while($row=mysql_fetch_array($result1))
                {
                    $eemp_id=$row["eemp_id"];

                echo "employee id is". $eemp_id;    
                echo "<tr>";
                 echo "<td>".$row[0]."</td>";
                  //echo "<td>".$row["id"]."</td>";
                 //$id=$row["id"];

                $to = $row[0];
                echo   " we found mail id".$to;
                $subject = "This is subject";
                $message = "This is simple text message from santulan regarding you have not "
                ."replied for the E-counseling chat for last 28 days ";
                $from = "no.reply@santulan.co.in";
                $header = 'From: '.$from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

                $retval = mail($to,$subject,$message,$header);
                if( $retval == true )  
                {
                echo "result found";
                echo "Message sent successfully from live.... $mail";
                }
                else
                {
                echo "Message could not be sent...";
                }
                     echo "</tr>";
                echo "no of rows: $num";
              echo "Mail is: $mail";

                }           
            }
        else
        {
        echo " no record found";    
        }               
        }
        else
        {           
        echo "Date difference not greater ";
        }
        }
        }
    ?>      
        </table>`enter code here`   
</body>

When I put this file at cron and I set my mail id for alerts, I get the following maul errors: 当我将此文件放在cron并设置警报的邮件ID时,出现以下恶意错误:

/home/santu/public_html/cron_job.php: line 1: syntax error near unexpected token newline' /home/santu/public_html/cron_job.php: line 1: ' /home/santu/public_html/cron_job.php:第1行:意外令牌newline' /home/santu/public_html/cron_job.php: line 1:附近的语法错误newline' /home/santu/public_html/cron_job.php: line 1: '

The file runs absolutely right when I run it manually.It looks like there are mostly some html error but I cant get it. 当我手动运行该文件时,该文件绝对正确运行。看起来似乎大多数html错误,但我无法获取。

It does depend a little on how your cron job is setup however normally.. 这确实取决于您的Cron作业的设置方式,但是通常情况下。

You cant run a cron job with the following at the top 您无法在顶部运行以下内容的cron作业

<!DOCTYPE html>
<html>
<head>
<title>MY Database</title>
</head>
<body>

you need 你需要

#! /usr/bin/php

(replacing the path to php as required) (根据需要替换php的路径)

Otherwise unix doesnt recognise it as a viable script and what to run it with - it doesnt care it says .php at the end 否则,unix无法将其识别为可行的脚本以及如何运行该脚本-它不在乎它的末尾显示.php

You do need also to remember that cron may not have picked up all the environment variables you have when you run it from the command line. 您还需要记住,当从命令行运行cron时,cron可能并未获取您拥有的所有环境变量。

so even if you run it as /usr/bin/php myfile.php 因此,即使您将其作为/ usr / bin / php myfile.php运行

it may not work the same, as commands may not be in your path that you had before. 它可能无法正常工作,因为命令可能不在您以前的路径中。

Also - its outputting html because you have coded html in it. 另外-它的输出html,因为您已经在其中编码了html。 If you arent going to be running this file from your website ever - then dont code it to do so. 如果您不打算从您的网站上运行此文件,请不要对其进行编码。 You can get it to output better plain text which normally is emailed to you on any output. 您可以获取它以输出更好的纯文本,通常将其通过任何输出通过电子邮件发送给您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM