Interview of senior engineer by PHPer in eight years (Reprinted)

Time:2020-10-26

This is a negative teaching material, I hope to arouse the vigilance of some programmers.

In the past half a month, after several interviews, I have almost set my own position – there is still a little distance from Tencent’s T3 position.

Because I have been used to staying in a small company for 6 years, no one in the company has surpassed me in technology. As the core of technology, I feel very good. Living in a small circle, I hardly take the initiative to learn about new technologies. Even I am not proficient in PHP and JS itself.

So when the accident happened, I found out how bad my skills were. Although I didn’t make special preparation for the interview before, I still had a big gap compared with the situation of looking for a job six years ago.

The following are some of the interview questions I met. I try to use what I know to make a statement. There will be many misunderstandings and omissions. I hope you can correct them.

Company 1:

1、mysql_ real_ escape_ string mysql_ escape_ What are the essential differences between strings, what are their uses, and why are they abandoned?

A: MySQL_ real_ escape_ String needs to connect to the database in advance, and can pass in the database connection in the second parameter (the previous connection will be used if it is not filled in)

Both of them are to escape the database insert data, but mysql_ real_ escape_ When string is escaped, the character set of the database connection is considered.

They are all used to make the data insert into the database normally and prevent SQL injection, but they can’t prevent SQL injection 100%.

Ask again: why can’t 100% prevent?

A: because the client-side code and server-side code are different, injection problems may occur, but in fact, this kind of scenario is rare.

Continued a: the reason why it is abandoned is that MySQL is no longer recommended by the government_ XX database operation mode, it is recommended to use PDO and mysqli, because MySQL I is better than MySQL in terms of performance and security.

The derived question is the connection reuse (persistence) problem of mysqli, which I did not answer well.

2. What is memory leak and how is JS memory leak produced?

A: a memory leak is because a piece of allocated memory can neither be used nor recycled until the browser process ends.

The reason for the leakage is that the closure maintains the local variables in the function and cannot be released, especially when the closure is used and there is an external reference and setinterval.

Note: I don’t think this answer is good, because it is definitely not the reason for closure.

I checked the information and answered this question from a relatively shallow perspective

There are several causes of leakage:

(1) The page element is deleted, but the event bound to the element is not deleted;

(2) The closure maintains the local variables in the function (external uncontrollable) so that they cannot be released;

(3) Unexpected global variables;

(4) The reference is deleted, but the reference within the reference still exists in memory.

From the above reasons, the root cause of the memory leak is that the reference cannot be recycled correctly, and the value type cannot cause the memory leak.

For each reference, there is its own reference count. When the reference count returns to zero or is marked to be cleared, the JS garbage collector thinks that the reference can be recycled.

3. What is closure and what is its relationship with prototype chain and scope chain

A: a closure is a function that exists in a function domain of a branch of the scope chain. The function can access the variables in the scope chain step by step until it is found. When the closure has external references, JS will maintain the memory state of the closure itself and its function scope chain.

Note: This is my own nonsense.

Continue to answer: it has nothing to do with the prototype chain. The prototype of a function is mainly used to implement inheritance. The prototype chain can be used to trace the inheritance relationship. Similar to the scope chain, all the properties are accessed level by level up until they are found. The top level of the prototype chain is null, which can be understood that all objects inherit to null, so the type of null is object.

Continued answer: the scope chain can be seen as a tree structure, which spreads down from the root node window. The lower level node can access the upper level node, but the upper level node cannot access the lower level node. The scope of the function generating the closure belongs to one of the nodes. After the downward diffusion, the closure function generates leaf nodes, and the leaf nodes can access each other. When the variables accessed are in the leaf When a node cannot be found, it searches the upper node until it is found. This concept is a bit similar to the attribute search on the prototype chain.

4. How many web pages can you open at the same time

Answer: 65535-1000 = 64535 (number of ports)

5. Can IP address be forged?

A: the HTTP header can be tampered with, but only x can be modified_ FORWARDED_ For, real IP address (Remote_ Addr) is very difficult to modify (unless it is the router to modify), because the real IP is the IP address of the underlying session, and because of the existence of TCP three-time handshake, the connection cannot be established, and the forgery is of little significance. As for UDP, UDP communication is generally used in the intranet.

6. There are 1 million prizes, and each person can win three times. How to control concurrency, and how to ensure the complete first come first served mode

A: millions of prizes are inserted into the database in advance after disruption. All winning operations can only be updated and cannot be inserted. The users who come in the lottery use memcahe atom lock to realize the automatic increase of the number of draw. When the number of lottery reaches 3, it will return the failure to win.

Another question: pre insertion requires a lot of resources. What if the number of prizes exceeds 100 million?

A: using the redis queue to store requests and running the daemons to issue awards asynchronously, the problem is that users can’t see the winning situation in real time.

Ask again: this certainly can’t do.

Re answer: using global memory lock to ensure that the lottery process is a single process running, but it will face large concurrent blocking problem.

Another question: memory is precious. What should we do without locking the memory? And if we encounter a 100 million prize pool, it is definitely not good to insert the database in advance. What should we do?

A: set the prize probability, which is divided into three tables, all using InnoDB engine, one record of winning prizes (insert a row in advance), one record of prize distribution, and one lucky draw (unique index of UIN). In case of large concurrency, the exclusive lock of MySQL is used for concurrency control. The process is as follows:

begin

Query the number of lottery draw users, add exclusive lock

Update / insert the number of user draw

Locking bank query release

Win the lottery results (after some prizes are distributed, the dynamic change probability)

Update distribution form

Insert winning record

commit

Ask again: encounter dirty read how to do?

A: I don’t know much about this

Another question: under what circumstances does InnoDB’s master thread fork other sub threads?

A: I don’t know

7. How is the data in the data link layer verified and what are the verification methods?

A: CRC32, other checks may be modulus check odd even number.

Note: answer a CRC check on the line.

8. What is the query time complexity of the B + tree and the hash table? Why does the database index refer to the B + tree storage instead of the hash table? Is there any other data structure in the database index storage?

A: O (log (n)), O (1)

Because the hash table is hash, thekey>’12’ does not work and has high spatial complexity.

Note: B + number determines the time complexity according to the number of layers. In the case of large amount of data, it is generally 4-5 layers, and then the dichotomy method is used to find the data in the page. The time complexity is far less than log (n).

9. How does Apache communicate with PHP? What is SAPI

A: using SAPI communication, SAPI is an external data transfer interface encapsulated by PHP. There are usually four running modes: CGI / fastcgi / cli / apache2handler.

10. PHP garbage collection mechanism?

A: garbage collection means that when the running state of PHP ends, such as exit / die / fatal error / script running ends, PHP needs to recycle the memory of variables and resources created during the running process.

Zend engine maintains a stack zval. Each variable and resource created will be pushed into the stack. The structure of each pushed array is similar: [refcount = > int, is_ Ref = > 0| 1, value = > Union, type = > string], when the variable is unset, ref = > 0 | 1, value = > Union, type = > string]_ If count becomes 0, it is recycled.

When the variable references itself, the synchronous recovery algorithm is used.

Note: php7 has rewritten the structure of ZAL.

11. Working principle of sizzle engine in jquery

A: nothing except until it’s the DOM element lookup engine.

12. The working principle of seajs, how to solve the problem of repeatedly loading the library and how to load the resources synchronously

A: set up a mapping relationship and cache it; resources can’t be loaded synchronously, just a callback is returned.

13. The difference between memredis and Memcache

A: there are different data structures that can be stored; redis supports persistent storage.

14. MD5 reverse principle

A: first look it up in a dictionary, and then try to crack it violently.

Ask again: is there no better way?

A: No.

Note: Well, in fact, there is no particularly good method. Only TB level massive feature database can be used to store it in the database, and then it will be partitioned and searched.

15. The parent method is protected and the child class is reconstructed to private. What happens?

A: fatal error will occur because inherited methods or properties can only maintain or enlarge permissions, and cannot be reduced. For example, it is feasible to change the protected overload to public.

16. During the period from inputting address and carriage return to completely displaying the content of a web page, the more detailed the better.

A:

0. Browser local cache matching;

1. Local hosts mapping comparison;

2. Local DNS cache resolution;

3. The server IP address is obtained by remote DNS resolution;

4. The browser sends TCP connection request packet (SYN);

5. The request packet is encapsulated in transport layer, network layer and data link layer, and arrives at router through network card;

6. The router forwards the data packet to the server of its operator;

7. The operator server reaches the designated IP address through the relay node through the shortest addressing path;

8. There may be reverse proxy or load balancing on the server side, which directly forwards the request to the upstream server. Of course, security defense rules can be formulated to directly discard the request packet;

9. The upstream server receives the connection request and returns (syn + ACK) when it is available;

10. The browser checks the ACK and sends it again (syn + ACK);

11. The server checks the ACK, switches the connection state to established, and then transmits the data packet according to the request;

12. When transform encoding is chunked, the browser starts to render the page;

13. Wave four times and close the connection;

14. Rendering data complete.

Note: there are a lot of things I don’t understand, some things are completely blind, because of time, I have time to draw them in detail.

17. The concept of keep alive

A: the long connection mechanism means that if the connection is not closed during the keep alive timeout time, it is no longer necessary to shake hands three times to transfer data again.

Note: there are many questions here, which need to be sorted out.

18. Linux file compression operation command, shell script, etc

Note: because the development is usually in the windows environment, lack of understanding of Linux, this piece is almost 0 points.

Company 2:

This is despised the most miserable one, first there will be a written test, relatively speaking, not complex, but some holes, many have forgotten.

What impressed me was that I said I was familiar with common design patterns and then asked me to draw UML class diagrams. Therefore, when writing a resume, it is better to write what I am very familiar with. If I only have a little knowledge, it is not necessary to put it in my resume.

Company 3:

Here are just a few questions

1. A relay server is designed to forward the requests from client a to client B;

2. What is the difference between MyISAM and InnoDB;

3. What are the causes of PHP process deadlock? How to check and recover automatically?

4. Class a {public function B ($a, $b, $c) {}};

How to use [‘b ‘= > 2,’ a ‘= > 1,’ C ‘= > 3] to call a:: B and assign values successfully?

5. The evolution history and new features of php5.2 – > php7.1?

6. Draw a TCP triple handshake diagram

At present, I am still looking for a job. In my opinion, 8-year-old programmers should not be like this. The lesson of boiling frogs in warm water is very painful. Fortunately, it is not too late to realize the problem. When you are 35 years old, it may be really late.


Note: This article is reproduced
Eight years of interview with PHPer senior engineer

Recommended Today

What black technology does the real-time big data platform use behind the glory of the king?

Hello everyone, I’m Xu Zhenwen. Today’s topic is “Tencent game big data service application practice based on Flink + servicemesh”, which is mainly divided into the following four parts: Introduction to background and Solution Framework Real time big data computing onedata Data interface service onefun Microservice & servicemesh 1、 Introduction to the solution framework and […]