Home Backend Development PHP Tutorial Video resource recommendation implemented by PHP e-commerce website product flash sale function

Video resource recommendation implemented by PHP e-commerce website product flash sale function

Aug 31, 2017 pm 03:07 PM
php Function accomplish

As we all know, for a product flash sale function with fierce traffic and extremely high stability requirements, traditional PHP technology is difficult to meet the requirements, so it requires the help of website architecture design, server configuration, load balancing, CDN acceleration, cloud analysis, redis It can be realized by various means. This course is an advanced PHP course. It mainly introduces the ideas of function implementation and does not involve the specific implementation of the code. Newbies should be careful!

Video resource recommendation implemented by PHP e-commerce website product flash sale function

Course playback address: http://www.php.cn/course/279.html

The teacher’s teaching style:

The lectures are friendly and natural, unpretentious, not pretentious, nor deliberately exaggerated, but talk eloquently and carefully, and the relationship between teachers and students is In an atmosphere of equality, collaboration, and harmony, silent emotional exchanges are carried out, and the desire and exploration of knowledge are integrated into simple and real teaching situations. Students gain knowledge through quiet thinking and silent approval

The more difficult point in this video is the flash sale project architecture - the data processing layer:

1 Flash Sale Business Analysis

Normal Electronics Business process (1) Query products; (2) Create orders; (3) Deduct inventory; (4) Update orders; (5) Payment; (6) Seller shipment

Characteristics of flash sale business (1 ) Low price; (2) Massive promotion; (3) Instantaneous sell-out; (4) Generally on the shelves at a scheduled time; (5) Short time, high instantaneous concurrency;

2 Flash Kill Technical Challenge

Assume that a website’s flash sale event only launches one product and is expected to attract 10,000 people to participate in the event. In other words, the maximum number of concurrent requests is 10,000. The technical challenges that the flash sale system needs to face are:

Impact on website business The Flash Sale activity is just an additional activity of website marketing. This activity has the characteristics of short time and large number of concurrent visits. If deployed together with the original application of the website, it will inevitably have an impact on the existing business and cause slight discomfort. Caution may cause the entire website to crash. Solution: Deploy the flash sale system independently, or even use an independent domain name to completely isolate it from the website.

Application and database load under high concurrency. Before the flash sale starts, users should constantly refresh the browser page to ensure that they will not miss the flash sale. If these requests follow the general website application architecture, access the application server and connect to the database. , which will cause load pressure on the application server and database server. Solution: Redesign the flash sale product page, do not use the original product detail page of the website, the page content is static, and user requests do not need to go through the application service.

Sudden increase in network and server bandwidth Assume that the product page size is 200K (mainly the product image size), then the required network and server bandwidth is 2G (200K×10000). These network bandwidths are due to the new increase in flash sale activities , exceeding the bandwidth normally used by the website. Solution: Because of the new network bandwidth added by the flash sale, you must re-purchase or lease it from the operator. In order to reduce the pressure on the website server, the flash sale product pages need to be cached in CDN, and the newly added export bandwidth also needs to be temporarily rented from the CDN service provider.

The rule of the game for direct ordering and flash sales is that you can only start placing orders for products after the flash sale. Before this time point, you can only browse product information and cannot place orders. The order page is also a normal URL. If you get this URL, you can place an order without waiting for the flash sale to start. Solution: In order to prevent users from directly accessing the order page URL, the URL needs to be made dynamic. Even the developers of the flash sale system cannot access the order page URL before the flash sale starts. The method is to add a random number generated by the server as a parameter in the order page URL, which can only be obtained when the flash sale starts.

How to control the lighting of the purchase button on the flash sale product page. The purchase button can only be lit when the flash sale starts. Before that, it is gray. If the page is dynamically generated, of course you can construct a response page output on the server side to control whether the button is gray or lit. However, in order to reduce the load pressure on the server side and make better use of performance optimization methods such as CDN and reverse proxy, this Pages are designed as static pages and cached on CDNs, reverse proxy servers, and even on user browsers. When the flash sale starts, the user refreshes the page and the request never reaches the application server. Solution: Use JavaScript script control to add a JavaScript file reference to the flash sale product static page. The JavaScript file contains the flash sale start flag; when the flash sale starts, a new JavaScript file is generated (the file name remains the same, but The content is different), update the flash sale start flag to Yes, add the URL of the order page and the random number parameters (this random number will only generate one, that is, the URL seen by everyone is the same, the server side can use redis Distributed cache server to save random numbers) and loaded by the user's browser to control the display of flash sale product pages. This JavaScript file can be loaded with a random version number (for example, xx.js?v=32353823) so that it will not be cached by browsers, CDNs, and reverse proxy servers. This JavaScript file is so small that even accessing the JavaScript file server every time the browser refreshes does not put much pressure on the server cluster and network bandwidth.

How to only allow the first submitted order to be sent to the order subsystem. Since there is only one user who can successfully flash sale the product, it is necessary to check whether an order has been submitted when the user submits the order. If an order has been submitted successfully, you need to update the JavaScript file, update the flash sale start flag to No, and the buy button turns gray. In fact, since only one user can successfully submit an order in the end, in order to reduce the load pressure on the order page server, the entrance to the order page can be controlled. Only a few users can enter the order page, and other users directly enter the flash sale end page. Solution: Assume that the order server cluster has 10 servers, and each server only accepts a maximum of 10 order requests. Before anyone successfully submits an order, if a server already has ten orders and some orders have not been processed, the possible user experience scenario is that the user clicks the purchase button for the first time and enters the completed page. If you refresh the page again, it may be processed by a server that has not processed any orders. When you enter the page for filling in orders, you can consider using cookies to deal with it, which is consistent with the principle of consistency. Of course, the least-connected load balancing algorithm can be used, and the probability of the above situation is greatly reduced.

How to check before placing an order

If there are more than 10 items, the completed page will be returned directly to the user;

If there are not more than 10 items, the user can enter and fill in the order and confirmation page;

has exceeded the total number of flash sale products, and the completed page will be returned to the user;

has not exceeded the total number of flash sale products, and is submitted to the sub-order system;

Check that the global Number of orders submitted:

The order server checks the number of order requests processed by the machine:

Flash sales are generally scheduled to be put on the shelves. There are many ways to implement this function. However, the better way at present is to set the shelf time of the product in advance. The user can see the product on the front desk, but cannot click the "Buy Now" button. But what needs to be considered is that someone can bypass the front-end restrictions and initiate a purchase directly through the URL. This requires clock synchronization on the front-end product page, as well as the bug page and the back-end database. The more control is on the back end, the higher the security. For timed flash sales, it is necessary to avoid unexpected effects caused by sellers editing the products before the flash sale. This particular change requires multiple evaluations. Editing is generally prohibited. If changes are needed, you can go through the process of data correction.

There are two options for reducing inventory. One is to take photos to reduce inventory. The other is to pay to reduce inventory. The currently adopted method of "photographing to reduce inventory" takes just a moment. The user experience will be better.

Inventory will cause the problem of "oversold": the quantity sold is more than the quantity in stock. Due to the problem of concurrent inventory updates, when the actual inventory is already insufficient, the inventory is still decreasing, resulting in the seller's product The number of units sold exceeded the flash sale expectation.

The above is the detailed content of Video resource recommendation implemented by PHP e-commerce website product flash sale function. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1272
29
C# Tutorial
1252
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles