PHP handles high concurrency issues

Source: Internet
Author: User
: This article mainly introduces PHP to handle high concurrency issues. if you are interested in the PHP Tutorial, please refer to it. In highly concurrent businesses, the accompanying problem is how to accurately and correctly process users' requests and respond quickly, the database may cause a sudden increase in concurrency and data inconsistency. So program design is crucial. Main scenarios include ticket snatching and seckilling...

1. use memcacheq Message Queue

The queue's first-in-first-out storage allows us to set the number of second-kill items as the upper limit and store them in the cache. when users request the server instantaneously, we can determine whether the current number of requests exceeds the total number of items, if the value is greater than the value, the system jumps to the static failure page. if the value matches the value, the system enters the next process of the program.

II. use memcached to throttling

You can reduce the pressure on the database by processing user requests one by one, and provide reliable data. you can use two caches to control the request's access to data. for example, you can set key1 to true, at this time, the user can grab and enter the subsequent process, change this value to false at the same time, other requests cannot enter (enter the wait, and recursively call ), the value of the current request is restored after it is processed. the actual situation depends on your needs.

III. distributed conditions

In a distributed server cluster, the number of products is evenly distributed to each server. the same way is to determine whether the products meet the requirements, as in solution 1.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above section introduces PHP's high concurrency processing, including some content, and hopes to help those who are interested in PHP tutorials.

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.