I开发者_如何转开发 am running a loop script in PHP command line, which send out emails to customers using PHPMailer. The problem I am receiving is that the command line script exits when the PHPMailer returns a false.
Here is the script pseudocode:
while(the loop is valid){
if(mail ID exists){
set_time_limit(30);
..compose mail..
if($mail->Send()){
..Mark as success in database..
usleep(10000);
} else {
..Mark as failure in database..
usleep(10000);
}
}
..continue loop..
}
If the $mail->Send()
returns a false, the script stops and exits. Is this an expected behaviour of PHP in command line? If that's the case, is there any way to tell PHP not to stop when it receives a false?
Thank you for any help.
I would guess that the $mail->Send()
function (or something else completely) is throwing an error which is halting the execution of your script.
I take it the values are not getting updated in the database either? This will be the case if so. Run the script with error reporting on to determine this.
error_reporting(E_ALL);
ini_set('display_errors', true);
Most likely the error handling routine (in the else branch) calls exit
or causes a fatal error that lets php bail out.
Add two lines of debug output to check whether the script enters and leaves the else branch (successfully).
while(the loop is valid){
[...]
} else {
error_log('Debug: Send() failed. Start error handling');
..Mark as failure in database..
usleep(10000);
error_log('Debug: Send() failed. End error handling');
}
[...]
精彩评论