Using the sleep function to solve the problem of timed deletion of unpaid orders

Source: Internet
Author: User
E-commerce website purchase of goods after the production of orders will generally have a payment aging problem
If the order is not paid within a certain amount of time after the user orders, cancel the order and release the remaining quantity of the goods occupied in the order
Collected the information on the Internet, there are generally the following methods
1) Mysql 5.1 can create timers later
2) Write a php page to delete the order and create a scheduled task on the server side: PHP removeexpiredorders.php
3) The user updates the order status when the order is displayed

Because I am not too understanding MySQL timer and how to create timed tasks, Method 1) and Method 2) temporary pass
Method 3) Due to the inability to release orders occupied by the number of items remaining pass

And then I was wondering if you could curl a checkpay.php page while the user confirms the order being generated
In the checkpay.php
Sleep (2*3600);//Set payment limitation of 2 hours
if (order[' status ']==0) {
/******* Delete the voided order and release the remaining number of items ******/
}

1.curl can set time-out, call Curl's page without waiting for the result of the Sleep page execution
2.checkpay.php no page output code, just the code of the operation of the database, search on the Internet this situation the sleep function consumes less system resources

Now I would like to discuss whether this method is feasible to implement the method of timing the failure order, and if there is any improper place, I hope the great God can correct it.


Reply to discussion (solution)

Sleep just hangs up the current program for several seconds
Neither the user nor the Web server will wait for you for 2 hours.
So it's not feasible.

Although there are timers above mysql5.1, you may not (not) use them, and MySQL in the real environment may not be 5.1.
You may not have permission to use the operating system's scheduled tasks
As for Method 3, "the number of items that cannot be released by order" is taken for granted, since the order can be deleted, it can be recycled to occupy

The most likely method is to call the order recycler when generating a page that needs to display the remaining quantity

Thank you moderator a lot of patience to explain, as the moderator said, in the need to show the remaining number of pages to recover the remaining items, for the best solution ~

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.