what I am doing is to write a PHP script which get's the user's email and the content they want to send and then use curl_exec to initiate a session and send to the server, and the server will do the rest based on which email service provider is associated.
But recently for one of our client, when they are submitting the request(forgot password or so), sometimes they received two automated emails(it is so weird that the duplicate email will only be triggered when it's their first time submitting the request of that day on that PC, after they triggered it once, no matter how many times they submit the request, no duplicate email at all).
I have also consulted the email service provider(Mandrill), and apparently they said they received two API call. And I have tested with a client. I have realized that after the user clicked (lets say) forgot password, only one rest call was sent to the php server. And Some how our database received two rest calls.
And I have tried really hard to debug it, but I could not solve it. So now I am trying to implement something which can stop the duplicate emails.
I am trying to make sure the following PHP script only run once within a very short amount of time(0.5 - 1 sec):
function post_json_and_decode ($url,$username=null,$password=null,$data=null)
{
$ch = curl_init($url);
$urldata = "{}";
if ($data === null)
$urldata = '{}';
else
$urldata = json_encode($data, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $urldata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($urldata),
$this->create_basic_authorization($username, $password)
)
);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result,true);
}
and I wonder if anyone can shred me some light this? as I have already searched a lot, and CRON doesn't seem to be the solution for me.