Use the sleep function to delete unpaid orders on a regular basis. after an order is generated for purchased items on an e-commerce website, there is usually a payment validity period.
After the user places an order and does not pay the order within a certain period of time, the order is canceled and the remaining number of items in the order is released.
I collected some online materials and found the following methods:
1) you can create a timer after Mysql 5.1.
2) write a php page for deleting orders and create a scheduled task on the server: php removeExpiredOrders. php
3) the user updates the order status when displaying the order
Because I am not familiar with mysql timers and how to create scheduled tasks, Method 1) and method 2) temporarily pass
Method 3) pass
Then I wondered whether the user could generate an order and curl a checkpay. php page
In checkpay. php
Sleep (2*3600); // set the payment validity period to 2 hours
If (order ['status'] = 0 ){
/******* Delete the invalid order and release the remaining number of items in use ******/
}
1. curl can set the timeout time. the page that calls curl does not have to wait for the execution result of the sleep page.
2. checkpay. php has no page output code. it is only the code used to operate the database. in this case, the sleep function does not occupy many system resources on the Internet.
Now I want to discuss whether this method is feasible to implement timed processing of invalid orders. Is there anything wrong with it?
Reply to discussion (solution)
Sleep only suspends the current program for several seconds.
Neither the user nor the web server will wait for you for two hours.
So it is not feasible
Although there is a timer above mysql5.1, you may not (don't want to) use it. In addition, mysql in the real running environment may not reach 5.1.
You may not have the permission to use scheduled tasks of the operating system.
As for Method 3, "the remaining quantity of goods occupied by the order cannot be released" is taken for granted. since the order can be deleted, it can be recycled.
The most possible method is to call the order recycling program when generating a page that requires displaying the remaining quantity.
Thank you for your patience. as the moderator said, recycling the remaining items on the page that requires displaying the remaining quantity is the optimal solution ~