rest - How to make sure PHP Scripts only run once within a very short amount of time(0.5 - 1sec) -
what doing write php script get's user's email , content want send , use curl_exec initiate session , send server, , server rest based on email service provider associated.
but 1 of our client, when submitting request(forgot password or so), received 2 automated emails(it weird duplicate email triggered when it's first time submitting request of day on pc, after triggered once, no matter how many times submit request, no duplicate email @ all).
i have consulted email service provider(mandrill), , apparently said received 2 api call. , have tested client. have realized after user clicked (lets say) forgot password, 1 rest call sent php server. , how our database received 2 rest calls.
and have tried hard debug it, not solve it. trying implement can stop duplicate emails.
i trying make sure following php script run once within 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 wonder if can shred me light this? have searched lot, , cron doesn't seem solution me.
Comments
Post a Comment