-
-
Save till/715511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
define("DBHOST", "localhost"); | |
define("DBUSER", "-mydb"); | |
define("DBPASS", ""); | |
define("DEFAULT_DB", "-mydb"); | |
define("MAILER_TABLE", "mail_queue"); | |
define("MAILER_LOCK_FILE", "/tmp/mailer_queue.lock"); | |
$fp = @fopen(MAILER_LOCK_FILE, 'x'); | |
if (!$fp) | |
{ | |
error_log("Mail queue already running!"); | |
exit; | |
} | |
require_once "Mail/Queue.php"; | |
require_once 'DB.php'; | |
$db_options['type'] = 'db'; | |
$db_options['dsn'] = 'mysql://' . DBUSER . ":" . DBPASS . "@" . DBHOST . "/" . DEFAULT_DB; | |
$db_options['mail_table'] = MAILER_TABLE; | |
$mail_options['driver'] = 'mail'; | |
$mail_queue =new Mail_Queue($db_options, $mail_options); | |
$mail_queue->setBufferSize(20); | |
$limit = 1300; | |
$db =& DB::connect('mysql://' . DBUSER . ":" . DBPASS . "@" . DBHOST . "/" . DEFAULT_DB); | |
if (PEAR::isError($db)) | |
{ | |
die($db->getMessage()); | |
} | |
while ($limit-- > 0 && $mail = $mail_queue->get() ) | |
{ | |
$result = $mail_queue->sendMail($mail); | |
if(PEAR::isError($result)) | |
{ | |
error_log($result->getMessage()); | |
$datetime = date('Y-m-d') . ' ' . date('H:i:s'); | |
$logs = $result->getMessage(); | |
var_dump($result); | |
$insert = " | |
insert into sh_mail_list_status | |
(`id_parent`, `campaign`, `subject`,`status`,`log`,`createdate`,`email`) values | |
( | |
'1', | |
'campaign', | |
'subject', | |
'fail', | |
'$logs', | |
'$datetime', | |
'{$mail->recipient}' | |
) | |
"; | |
$res = $db->query($insert); | |
if (PEAR::isError($res)) | |
{ | |
die($res->getMessage()); | |
} | |
} else { | |
$datetime = date('Y-m-d') . ' ' . date('H:i:s'); | |
//$logs = $result->getMessage(); | |
//error_log($result->getMessage()); | |
var_dump($result); | |
$insert = " | |
insert into sh_mail_list_status | |
(`id_parent`, `campaign`, `subject`,`status`,`log`,`createdate`,`email`) values | |
( | |
'1', | |
'campaign', | |
'subject', | |
'ok', | |
'$logs', | |
'$datetime', | |
'{$mail->recipient}' | |
) | |
"; | |
$res = $db->query($insert); | |
if (PEAR::isError($res)) { | |
die($res->getMessage()); | |
} | |
} | |
$mail_queue->deleteMail($mail->getId()); | |
usleep(250000); | |
} | |
fclose($fp); | |
unlink(MAILER_LOCK_FILE); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment