I have an mailing list and regurally send information to it.
This mailing list has grown up and now it’s too big to send it at a commercial time because opens too many connections and the server is inaccessible.
So I made a bash script to call a PHP file at night (4AM) that checks if there is any newsletter scheduled to send and if there is, send it.
BASH SCRIPT
#!/bin/sh
senddate=$(date +"%Y-%m-%d")
url=https://www.my.url/check_to_send_maillist.php?date=$senddate\&autosend=1
wget -O /my/log/dest.log --http-user=myuser --http-password=mypass $url
PHP SCRIPT
$date=$_GET["date"];
if($date<>""){
$sql="select newsletters_id from " . TABLE_NEWSLETTERS . " where send_date='" . $fecha . "'";
$nid=executequery($sql);
if($nid<>""){
$url="https://www.my.url/send_newsletter.php?page=1&nID=%s&action=confirm_send&autosend=1";
$url=sprintf($url,$nid["newsletters_id"]);
header('location:' .$url);
}
}
The tests were OK, and everything I did worked fine. When I used it with the real maillist the PHP script called 3 times to the URL that sends the newsletters so my customers received the newsletter 3 times. My maillist is about 40,000 addresses (yes I know I should use an external service)
Apache log
-BASH SCRIPT
server_ip - http_user [14/Dec/2012:04:00:02 +0100] "GET /check_to_send_maillist.php?date=2012-12-14&autosend=1 HTTP/1.0" 302 - "-" "Wget/1.10.2"
-PHP SCRIPT
server_IP - http_user [14/Dec/2012:04:04:59 +0100] "GET /my_send_script.php?page=1&nID=nid&action=confirm_send&autosend=1 HTTP/1.0" 200 21454 "-" "Wget/1.10.2"
server_IP - http_user [14/Dec/2012:04:20:01 +0100] "GET /my_send_script.php?page=1&nID=nid&action=confirm_send&autosend=1 HTTP/1.0" 200 21454 "-" "Wget/1.10.2"
server_IP - http_user [14/Dec/2012:06:05:38 +0100] "GET /my_send_script.php?page=1&nID=nid&action=confirm_send&autosend=1 HTTP/1.0" 200 268 "-" "Wget/1.10.2"
Why is the header location making multiple calls to the script? How can I force to make just one call?
Any suggestion to do it in a different way?.
Any help will be appreciated
After hole day looking for reason and/or solution for the problem I found it.
By default WGET tries 20 times to open the URL if it gives a timeout.
My script sends the emails was giving a timeout and so WGET tried again and again.
I chaged the WGET command to
–tries=1 forces WGET to try just once to open the script, even if gives timeout.
-T 4 set the timeount to 4 seconds
And worked fine.
Thanks for the help.