How does php merge transactions?

Source: Internet
Author: User
For example, user A spent two yuan to buy 100 bottles of water today. The market price is now 2 fast money, and then submit A ticket: when the market price rises to 2.5 yuan, he will sell 100 bottles. A is just waiting for A person to buy B User: now the market is assumed to be 3 yuan; then the order of 2.5 yuan to buy 50 bottles. Question: How does PHP use queue to enable automatic purchase of B users?
  • User A spent two yuan today to buy 100 bottles of water; the market is now two quick money; then the ticket: when the market rose to 2.5 yuan to sell 100 bottles. A. Just wait for someone to buy it.

  • User B: the current market price is assumed to be 3 RMB, and then 50 bottles will be purchased for 2.5 RMB for a ticket.

Problem

PHP uses queue to realize that user B automatically buys 50 bottles of user. B. The transaction is completed. The transaction of A has not been sold out yet, and the ticket is still pending; how to implement this transaction for N users.

Description
  • The above example is interpretedStock order pendingIt's easy to understand.

Reply content: for example
  • User A spent two yuan today to buy 100 bottles of water; the market is now two quick money; then the ticket: when the market rose to 2.5 yuan to sell 100 bottles. A. Just wait for someone to buy it.

  • User B: the current market price is assumed to be 3 RMB, and then 50 bottles will be purchased for 2.5 RMB for a ticket.

Problem

PHP uses queue to realize that user B automatically buys 50 bottles of user. B. The transaction is completed. The transaction of A has not been sold out yet, and the ticket is still pending; how to implement this transaction for N users.

Description
  • The above example is interpretedStock order pendingIt's easy to understand.

This problem has nothing to do with the language.

Two queues are required. one is used to store "buy" and the other is used to store "sell". The queues are sorted by price and the same price is sorted by time.

Then, the program constantly compares the highest and lowest selling prices. if there is an overlap between the two, the transaction price is calculated based on the selling price.

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.