I belie the reason is too many REQUEST coming to ipn_main_handler.php for same Checkout. so it start to process all POST request parallel and this causes duplicate order.
because the code ipn_main_handler.php already have duplicate request check control. so why this control not works lets see step by step
PHP Code:
$lookupData = ipn_lookup_transaction($_POST);
.....
$new_record_needed = ($txn_type == 'unique' ? true : false);
1.POST1 comes to ipn_main_handler.php
2.POST1 start processing check is there same PayPal request processed NO (check paypal table)
3.POST1 INSERT New Order to orders table
4.POST2 comes to ipn_main_handler.php
5.POST2 start processing check is there same PayPal request processed NO (check paypal table) (NO Because We haven't Insert POST1 row to paypal table
6.POST1 INSERT New Order to orders table
7.POST1 insert row to paypal table
8.POST2 insert row to paypal table
as you can see there is time lag between 7. step and 5. step. because of this parallel processing, is unique papal order checking fails and system process both post data as a new order.
i checked the Apache behavior with following code. when i send a two request from different browsers it procesed same page at same time(paralley).
PHP Code:
for($i=0;$i<8;$i++)
{
echo "$i. ".date("H:i:s", time())." <br>";
sleep(1);
}
and solution for this problem is using a table which keeps txn_id | (and process status)
and before start to process
1.update table txn_id|inprogress
2.second Post data checks if its in in progress then wait 5 seconds and check again until first process changed to txn_id|done
it have same weakness but if you don't use auto increment key. sytem have to wait for eacother because of SQL insert integrity or it gives duplicate key error.
This is my Theory of Duplicate orders. if you have any comments or different views on this analyze i love to hear. i have to solve duplicate problem.
anyone solved the problem ?? please share your solution...
thanks
Bookmarks