简体   繁体   中英

How to Tackle Cron Job Running Errors

I have a cron job (PHP) to get the commission of sales for N sales persons. It runs once in a month.

It has a number of criteria to calculate the commission for each sales person and can be updated by Admin.

What is best method to check whether the cron has run for all the sales persons, if not how can I get the details and rerun the cron?

Note: Using MySql

Please help

Cpanel cron jobs usually have an option for cron email. Which sends the results of the cron job to an email address. If you are having trouble with the cron job, set it to run every minute so you can get the email output and go from there.
Another option would be to add a php mail function to the script the cron job is executing:

<?PHP

//mail variables    
$emailAddress = "your@email.net";  

$subject = "Email Subject";    

$message = "Sales person 1 commission = $salesPersonOneVariable";  
$message.= "Sales person 2 commission = $salesPersonTwoVariable";    
$message.= "Sales person 3 commission = $salesPersonThreeVariable";   

$headers = "MIME-Version: 1.0" . "\r\n";    
$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";    
$headers.= 'From: noreply@yourdomain.com' . "\r\n" .      
            'Reply-To: noreply@yourdomain.com' . "\r\n" .        
            'X-Mailer: PHP/' . phpversion();

//mail function    
mail($emailAddress, $subject, $message, $headers);    

?>

With this you can add any information/variables from the script into the $message variable so that you can verify certain parts of the script are completing successfully.
The headers give you the option to include html in the email if needed.

* * 1 * *  php /yourjob.php >> /var/log/monthly_sales.log

Do something like that, echo out all your debug info into a log file, then check that logfile to see what happened, or what went wrong. Turn error_reporting on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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