This is a negative teaching material, hope also can cause the vigilance of part programmer.

In the last half a month, after several interviews, almost have their own positioning ———— distance from Tencent T3 post or a little distance.

Since I have been working in a small company for 6 years, no one in the company is better than me in terms of technology. As a technical core, I feel very good. Living in a small circle, I hardly take the initiative to learn about new technologies, and I am not even proficient in PHP and JS.

So when something happened, I realized how out of touch my skills were. Although I had not prepared for the interview before, there was a huge gap between me and the job hunting situation six years ago.

The following is part of the interview questions I have met. I try to use my knowledge to make statements. There will definitely be many misunderstandings and omissions, so I hope you can correct them.

Company 1:

Mysql_real_escape_string what is the essential difference between mysql_escape_string and mysql_real_escape_string?

A: Mysql_real_escape_string requires a pre-connection to the database, and can be used when the second parameter is passed to the database connection (otherwise, the previous connection is used). Both escape the database insert data, but when mysQL_real_escape_string escapes, The character set of the database connection is considered. They are used to allow data to be inserted into the database and prevent SQL injection, but they are not 100% SQL injection proof.

Ask again: why can’t 100% prevent?

A; Injection problems can arise because of the difference in client-side and server-side coding, but this scenario is rare.

Deprecated because mysql_xx is no longer recommended. Pdo and mysqli are recommended because mysqli is better than mysql in terms of performance and security.

The resulting problem is connection reuse (persistence) for mysqli, which I didn’t answer well.

2, what is a memory leak, js memory leak how?

A: A memory leak is because a block of allocated memory can neither be used nor reclaimed until the browser process terminates.

The leak occurs because closures hold local variables inside functions and cannot be released, especially if closures are used with external references and setintervals.

  • Note: I don’t think this is a good answer because it’s definitely not the closure.

I looked up the data and answered the question from a more shallow perspective: there are several reasons for leakage: (1) the page element is deleted, but the event bound to that element is not deleted; (2) Closures maintain local variables inside 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 is still in memory. From the above point of view, the root cause of memory leaks is that references are not recycled properly, and value types do not cause memory leaks. For each reference, it has its own reference count, and when the reference count goes to zero or is marked clean, the JS garbage collector considers the reference recyclable.

What are closures and how do they relate to prototype chains and scope chains

A: A closure is a function that exists in the function domain of a branch of the scope chain, and that function can access variables on the scope chain step by step until it finds them. When a closure has an external reference, JS maintains the in-memory state of the closure itself and of the function scope chain.

  • Note: THIS is my own nonsense.

Continue to answer: The prototype chain can be used to trace the inheritance relationship. Similar to the scope chain, it is used to access properties step by step until they are found. The top layer of the prototype chain is NULL, which can be understood as all objects inherit to NULL. So null is of type Object.

Continue to answer: Scope chain can be thought of as a tree structure, by the root node window downward diffusion, lower nodes can access the upper nodes, but don’t have access to the lower top node, produce the closure function scope belong to nodes in a downward diffusion after closure function leaf nodes, leaf nodes can visit each other between, When the accessed variable cannot be found in the leaf node, the upper node is searched until it is found, a concept somewhat similar to property lookup on the prototype chain.

A computer configuration infinite good, can open how many pages at the same time

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

5. Can IP addresses be forged?

A: The HTTP header can be tampered with, but only X_FORWARDED_FOR can be changed. The real IP address (REMOTE_ADDR) is difficult to change (unless the router changes it) because it is the underlying session IP address and the connection cannot be established due to the TCP three-way handshake. As for UDP, it is generally used for Intranet communication.

6, there are 1 million prizes, each person can win three times, first come, first served, how to control the concurrency, can not send out, and ensure a complete first come, first served mode

A: Millions of prizes in the disruption of the pre-insert database, all winning operations, can only update, not insert. Users who enter the lottery use memcahe atomic lock, realize the number of lottery increases, when the number of lottery reaches 3, return not winning.

Q: Pre-insert requires a lot of resources, what if the number of prizes is 100 million?

A: The problem with using redis queues to store requests and running daemons to award prizes asynchronously is that users can’t see their winnings in real time.

Ask again: That’s not going to work.

A: Use global memory locking to ensure that the raffle is a single process running, but with large concurrent blocking problems.

Ask again: memory is more precious, how to do without memory lock, and if the situation of 100 million prize pool, pre-insert database is not good, how to do?

A: Set the prize probability, divided into three tables, all using innoDB engine, one to save the winning record (pre-inserted one line), one to save the prize distribution overview, one to save the user lottery situation (UIN unique index), in the case of large concurrency, use mysql exclusive lock for concurrency control. The process is as follows:

begin

Query user lottery times, add exclusive lock

Updates/inserts to user sweepstakes

Lock rows to query the provisioning status

Get lucky draw results (dynamic probabilities change after some prizes are handed out)

Update the release table

Insert the winning record

commit

Copy the code

Ask again: encounter dirty read how to do?

A: I don’t know much about it

When does innoDB’s master thread fork other child threads?

A: I don’t know

7. How to verify data at the data link layer and what are the verification methods?

A: CRC32, other check may be to take the module check odd even bar.

  • Note: a CRC check should be answered.

8, what is the query time complexity of b+ tree, what is the hash table, why are database indexes stored in B + tree instead of hash table, are there other data structures for database index storage?

A: O(log(n)), O(1) Because the hash table is hashed, it does not work when key>’12’ is encountered, and the space complexity is high.

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

How does Apache communicate with PHP? What is SAPI

Answer: use the sapi communications, sapi is PHP encapsulation of external data transmission interface, usually with cgi/fastcgi/cli/apache2handler four operation modes.

PHP garbage collection?

A: Garbage collection refers to the need for PHP to reclaim the memory of variables, resources, and resources created during the execution of PHP at the end of the execution state, such as exit/die/ fatal error/script completion.

The ZEND engine maintains a stack, zVal, into which each created variable and resource is pushed. Each pushed array has a similar structure: [refcount = > int, is_ref = > 0 | 1, value = > union, type = > string], variable is unset, ref_count if become 0, is recycled. When a variable loop references itself, the synchronous collection algorithm is used for collection.

  • Note: PHP7 has rewritten the zal structure.

How jquery’s Sizzle engine works

Answer: Nothing except until it’s a DOM element lookup engine.

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

A: Establish mappings and cache them; The resource is not actually loaded synchronously, only a callback is returned.

13. Differences between Memcache and Redis

A: Different data structures can be stored; Redis supports persistent storage.

14. Md5 reverse principle

A: Use the dictionary first, then try brute force.

Ask again: isn’t there a better way?

A: No. Note: Well, in fact, there is really no good way, but to use terabytes of massive database with data storage, and then fragment search.

15. What happens if the parent method is protected and the subclass refactors to private?

A fatal error occurs because inherited methods or properties can only maintain or amplify permissions, not shrink them. For example, it is possible to override protected to public.

A web page from the input address enter, to the complete display of the content of the web page during this time, what to do, the more detailed the better.

A: 0. Browser local cache matches; 1. Compare the local hosts mapping. 2. Local DNS cache resolution; 3. Obtain the SERVER IP address by remote DNS resolution. 4. The browser sends a TCP connection request packet (SYN). 5. The request packet reaches the router through the transmission layer, network layer and data link layer and is encapsulated through the nic. 6. The router forwards data packets to the carrier server. 7. The carrier server reaches the specified IP address through the relay node through addressing shortest path; 8. There may be reverse proxy or load balancing on the server, which directly forwards requests to the upstream server. Of course, you can also make security defense rules and directly discard request packets. 9. When the upstream server receives the connection request, it returns (SYN + ACK) if it is available. 10, browser check ACK, send again (SYN + ACK); 11. The server verifies ack to switch the connection state to ESTABLISHED, and then transmits data packets according to the request. 12. When transform-encoding is chunked, the browser renders the page; 13, four times waved, connection closed; 14. Rendering data is completed.

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

17. Concept of keep-alive

A: Long connection mechanism, which means that if the connection is not closed within keep-alive-timeout, three handshakes are no longer required for data transmission again.

  • Note: there are also many questions that need to be clarified.

Linux file compression operation commands, shell scripts, etc

Note: Because the development is usually in the Windows environment, the lack of understanding of Linux, this part is almost 0 points.

The company 2:

This is the most despised one, first there will be a written test, relatively not complicated, but some pits, many have forgotten.

What impressed me was that I said I was familiar with common design patterns, and then asked to draw UML class diagrams, I was confused, so when writing a resume, it is best to write something you are very familiar with, if only a little knowledge, there is no need to put it in the resume.

The company 3:

Here are just a few of the questions asked:

1. Design A relay server to forward the request of client A-> client B;

2. What is the difference between MyISam and InnoDB?

3. What is the cause of PHP deadlock? How to automatic troubleshooting and automatic recovery?

Public function b($A, $b, $c){}}; How to use [‘ b ‘= > 2,’ a ‘= > 1,’ c ‘= > 3), to a: : b make calls, and the assignment?

5, PHP5.2 -> PHP7.1 version evolution history, new features, etc.?

6. Draw a TCP three-way handshake

I am still looking for a job. In my opinion, a programmer who has been working for 8 years should not be like this. The lesson of boiling frogs in warm water is very painful, but it is not too late to realize the problem.

Reproduced from:whig