A summary of new PHP interview questions for 2021 spring recruitment, Baidu, Ali, Meituan and other big companies (2)

Gold three silver four started, so it took a long time to collect and sort out this set of PHP interview questions, I hope it will be helpful to everyone~

The blogger also organized a large number of interview questions into a PHP interview manual,

It is a PDF version, and there is a way to get it at the end of the article, so if you are interested.

1.How does the shopping cart work?

Answer: The shopping cart is equivalent to the shopping cart of the supermarket in reality. The difference is that one is a physical car and the other is a virtual car. Users can jump between different pages of the shopping website to buy their favorite products. When they click to buy, the product is automatically saved in your shopping cart. After repeated purchases, the selected products are finally placed in The shopping cart is unified to the checkout counter, which is also trying to let customers experience the feeling of shopping in real life. The server tracks the actions of each user to ensure that each item has its own owner at the time of checkout.
Mainly involves the following points:

    1. Add goods to the shopping cart, that is, order
    2. Delete the ordered goods in the
    shopping cart 3. Modify the order quantity of a book in the
    shopping cart 4. Clear the shopping cart
    5. Display the list and quantity of the goods in the shopping cart, price

The key to implementing a shopping cart is that the server recognizes each user and maintains contact with them. But the HTTP protocol is a "Stateless" protocol, so the server cannot remember who is purchasing the product. When the product is added to the shopping cart, the server does not know what is in the shopping cart, making the user different The shopping cart cannot be "carried with you" when jumping between pages, which causes certain difficulties in the realization of the shopping cart.
At present, the realization of shopping cart is mainly through cookie, session or combined with database. Let's analyze their mechanism and function.

cookie A
cookie is a piece of information generated by the server and stored on the client. It defines a mechanism for the Web server to store and return information on the client. The cookie file contains the domain, path, lifetime, and variable values ​​set by the server. When the user visits the same Web server in the future, the browser will send the cookie to the server as it is. By allowing the server to read the information previously saved to the client, the website can provide a series of conveniences for the viewers, such as identifying the user's identity during online transactions, avoiding the user from re-entering the name and password, and the homepage of the portal website when the security requirements are not high. Customized, targeted advertising, etc. Using the characteristics of cookies, the functions of WEB applications are greatly expanded, not only can establish the connection between the server and the client, because the cookie can be customized by the server, it can also store the shopping information generated cookie value on the client, thereby realizing the shopping cart Features. Using cookie-based methods to implement a session or shopping cart between the server and the browser has the following characteristics:

1. The cookie is stored on the client and occupies very few resources. The browser allows to store 300 cookies, each of which is 4KB in size, which is sufficient to meet the requirements of the shopping cart and also reduces the load on the server;
2. The cookie is The browser is built-in and easy to use. Even if the user accidentally closes the browser window, as long as the information in the shopping cart is within the validity period defined by the cookie, the information in the shopping cart will not be lost;
3. The cookie is not an executable file, so it will not be executed in any way, so it will not bring Virus or *** user system;
4. Cookie-based shopping cart requires that the user's browser must support and set to enable cookies, otherwise the shopping cart will be invalid;
5. There are disputes about cookie infringement of visitors' privacy, so some The user will prohibit the cookie function of this machine.

session

Session is another way to implement a shopping cart. Session provides the function of saving and tracking the user's status information, so that the variables and objects defined by the current user in the session can be shared between pages, but cannot be accessed by other users in the application. The most significant difference between it and cookies is , Session stores the user's private information during the session on the server side, which improves security. After the server generates the session, the client will generate a sessionid identification number and save it on the client to maintain synchronization with the server. This sessionid is read-only. If the client disables the cookie function, the session will be transferred between pages by appending parameters to the URL or implicitly submitting it in the form. Therefore, the use of session to implement user management is more secure and effective.
Similarly, a shopping cart can also be implemented using session. The characteristics of this method are:

1. Session uses a new mechanism to maintain synchronization with the client, and does not depend on client settings;
2. Compared with cookies, session is information stored on the server side, so it is more secure, so it can mark identity, shopping and other information Stored in the session;
3. The session will take up server resources and increase the load on the server side, especially when there are many concurrent users, it will generate a large number of sessions, which will affect the performance of the server;
4. Because the information stored in the session is more sensitive and based on The file format is stored in the server, so there is still a security risk.

The method of combining with the database
is also a common mode at present. In this method, the database assumes the role of storing shopping information, and the session or cookie is used to track users. This method has the following characteristics:

1. The database and cookie are respectively responsible for recording data and maintaining sessions. They can play their respective advantages to improve security and server performance;
2. For every shopping behavior, a connection with the database must be directly established until the table is checked. After the operation is completed, the connection is released. When there are many concurrent users, it will affect the performance of the database. Therefore, this puts forward higher requirements on the performance of the database;
3. The support of the client is required to maintain the session with the cookie.

Various ways to choose:
Although cookies can be used to implement shopping carts, they must be supported by the browser. In addition, they are information stored on the client side, which is very easy to obtain, so this also limits it to store more and more importantly. Information. Therefore, generally cookies are only used to maintain a session with the server. For example, the largest Dangdang online bookstore in China uses cookies to maintain contact with customers, but the biggest disadvantage of this method is that if the client does not support cookies, the shopping cart will become invalid.
Session can maintain a conversation with both parties to the transaction well, and the settings of the client can be ignored. It has been widely used in shopping cart technology. However, the file attribute of the session still leaves a security risk.
Although the method of combining the database solves the above problems to a certain extent, it can be seen from the above example: this kind of shopping process involves frequent operations on the database tables, especially when the user purchases a product every time. Connecting to the database increases the load on the server and database when there are many users.

2.What should I pay attention to when the redis message queue is first in, first out?

Answer: Usually a list is used to implement queue operations, so there is a small limit, so the tasks are unified first-in-first-out. If you want to prioritize a certain task, it is not easy to handle it. This requires priority in the queue. Concept, we can prioritize high-level tasks. There are several ways to achieve:
1) Single list implementation: The normal operation of the queue is left in and right out (lpush, rpop) in order to process high-priority tasks first. When it comes to a high-level task, you can directly jump in the queue and put it directly into the head of the queue (rpush). In this way, when you get a task from the head of the queue (on the right), you get the high-priority task (rpop).
2) Use two A queue, a normal queue, an advanced queue, put different queues according to the level of the task, it is also very simple to get the task, the BRPOP command of redis can take values ​​from multiple queues in order, and BRPOP will follow the given key View sequentially, and pop an element at the end of the first non-empty list found, redis> BRPOP list1 list2 0

list1 as a high priority task queue

list2 as a normal task queue

In this way, the high-priority tasks are processed first, and when there are no high-priority tasks, ordinary tasks are obtained.

Method 1 is the simplest, but the actual application is relatively limited. Method 3 can achieve complex priority, but the implementation is more complicated, which is not conducive to maintenance

Method 2 is the recommended usage, which is most suitable for practical applications

3. What are the problems with the modules you are responsible for?

Answer: In the B2B e-commerce project that I am responsible for, I was in charge of the order module at the time. Because the customer selected the products of multiple merchants at a time, an order was finally generated, so that our platform did not know this when the merchant settled. Which merchant should be paid for than the fee? At this time, our group has discussed that it needs to involve order splitting, that is to say, after the user clicks to pay, if there are multiple items and they are not in the same store, then order splitting will be used. For example, if there are two items and they are not in the same store, generate two sub-order numbers under the original order number and modify the order numbers of the two items in the order table. Finally realized the distribution management of commodities and solved our problems.
I think in the development process, there are nothing more than two problems. One is technical level. I think that as long as you have perseverance and enthusiasm, there will be no problems that you can't find. The other is communication. Communication is the most important in any place and any time, especially when we do development. Failure to communicate well will affect the progress of the entire project. I am a very communicative person, so this point is also important. No big problem.

4. How does the user place an order?

Answer: It is judged whether the user is logged in, and it is not allowed to place an order without logging in. After logging in, you can place an order and generate a unique order number. At this time, the status of the order is unpaid.

5. How is the e-commerce login realized?

Answer: It is divided into ordinary login and third-party login. Let’s talk about the third-party login. The third-party login mainly uses the author protocol. I will take the third-party login of QQ as an example to illustrate: When the user is on our site When requesting a third-party login of QQ, our site will guide the user to jump to the QQ login authorization interface. When the user enters QQ and password and successfully logs in, it will automatically jump back to the callback page set by our site with a code parameter. Then you use the code to request the authorization page of QQ again, and you can get an access token (access token) from it. Through this access_token, we can call the interface that QQ provides to us, such as obtaining open_id, which can obtain the basic information of the user. . After obtaining it, we need to bind the user's authorization information and open_id with the ordinary users of our platform. In this way, whether it is an ordinary user login or a third-party login user, the login can be realized.

6.How is the interface security handled?

Answer: We did this at the time. We used HTTP POST to digitally sign fixed parameters + additional parameters and used md5 encryption. For example: I want to get a message through the title, and use the message title + date + on the client side. A key agreed upon by both parties is encrypted by md5 to generate a sign, and then passed to the server as a parameter. The server uses the same method for verification. How to accept the sign is the same as the value calculated by the algorithm. It proves to be A normal interface request, we will return the corresponding interface data.

7. What technology is used to send SMS and where can I call it?

Answer: I mainly use the third-party SMS interface. When I apply for the interface, I configure the corresponding information, and then call it where the SMS verification is needed on our site. We usually use it during user registration.

8. What difficulties do you encounter at work?

Answer: Generally speaking: I mainly encountered these few problems at work which are more difficult to deal with:
①When I was working before, I found that there were often temporary needs that disrupted my plan, and sometimes the task was not completed. I have to do other tasks. At the end of the last day, there are a lot of big and small things, but they haven’t been done very well. I will summarize them later. I will prioritize all of these. When encountering temporary needs, follow the priorities. Re-format existing tasks and temporary tasks to ensure efficient completion of high-priority tasks within the specified time.
②When working on project requirements, when encountering people with poor understanding, they are easy to get angry when communicating and affect their emotions. In the end, they can't achieve the desired effect. Later, every time I get to this kind of time, I usually use some paper-based, more vivid things to communicate in a way that both parties agree and understand, which reduces a lot of unnecessary troubles. Everyone knows that for programmers, changing requirements is a very painful thing, so early communication is very important.
③There is one more thing. My previous leader didn't know much about technology, so every time a new demand came out, we always asked us to complete it in a short period of time. If it didn't complete it, we would be suspected of ability problems. Of course, every leader hopes that his employees can complete tasks as soon as possible, reduce costs, and improve efficiency. At this time, I will refine our needs, list the key points and difficulties, do a good job of time planning, patiently communicate with the leaders, the importance of each point of the project and the proportion of time spent, to ensure that the planning is Complete the task with quality and quantity within the time point. Gradually, it has been recognized by the leader. In fact, the leader is not blindly unreasonable. As long as you plan things well, you can get the highest value at the lowest cost. Everyone is easy to understand.

9. How can the user directly add to the shopping cart without logging in?

Answer: The user can save the information of the product to be purchased (such as the ID of the product, the price of the product, the sku_id of the product, the number of purchases, and other key data) without logging in, in the case of logging in. Save the contents of the cookie to the database and clear the data in the cookie.

10. Have you ever written an interface? How do you define the interface?

Answer: I have written. There are two types of interfaces: one is a data-type interface, and the other is an application-type interface.
Data interface: It is a certain "structure" that is more abstract than an abstract class—it is not actually a class, but a certain grammatical structure like a class. It is a structural specification that regulates the format in which our class should be defined, generally It is used when the team is relatively large and there are many branches.
Application interface: API (application interface) is an entry for external access to data.
I am mainly involved in the preparation of the interface in the development of the APP. We will provide them with the corresponding data for what kind of data the client needs. The data is in json/xml The format is returned, and the corresponding interface document is attached.

11.sku reduced inventory?

Answer: SKU = Stock Keeping Unit (Stock Keeping Unit)
is the unit of stock in and out measurement, which can be in units of pieces, boxes, pallets, etc. SKU is the unit of inventory, which distinguishes single products.
It is the most commonly used in clothing and footwear products. For example, a SKU in textiles usually means: specifications, colors, and styles.
When designing the table, not only is there a product table, but there is a total inventory in the product table. We also need to involve a SKU table with SKU inventory and unit price fields. Every time a user purchases a product, what they actually buy is SKU. Commodities, so that after the order is successfully placed, the corresponding SKU inventory should be reduced according to the unique SKU number of the purchased product. Of course, the total inventory of the product is stored in the product master table, and the amount of inventory in the total inventory needs to be reduced.

To be continued~~~~~

Follow the WeChat public account: PHP God , and then reply to the " Interview Manual " to get it~

Guess you like

Origin blog.51cto.com/15115111/2668943