Summary of the interview questions of the latest PHP senior engineer in large factory in 2020 (3)

Time:2021-3-1

Summary of the interview questions of the latest PHP senior engineers in large factories in 2020 (1)

Summary of the interview questions of the latest PHP senior engineers in large factories in 2020 (2)

81. A refers to B, and an error is reported. The class in C is repeatedly defined. What’s the problem with circular reference

82. The salary of employee 3 below is higher than that of the supervisor. An SQL query finds the supervisor whose salary is lower than that of the subordinate

id username salary pid
1 a 3000 null
2 b 8000 null
3 c 5000 1
4 d 6000 3
SELECT a.*, b.*
FROM `user` as a
LEFT JOIN `user` as b ON a.pid = b.id AND a.salary > b.salary
WHERE b.id > 0;

82. There is a polygon composed of n points in a coordinate system. Now there is a coordinate point. Write code or ideas to judge whether the point is in the polygon

83. If there is a deadlock in the database, how do you check and judge if there is a deadlock?

84. Write a program to find the longest substring

85. Analyze a problem: the PHP FPM log is normal, but the client has timed out. What do you think might be the problem? How to check?

Check the nginx log, whether the request reaches nginx and whether it is forwarded to PHP FPM normally

86. The workflow of nginx can be described by drawing

87. What are the methods of interprocess communication

  1. The Conduit

Pipes are divided into famous pipes and unnamed pipes

Anonymous pipeline is a kind of half duplex communication mode, data can only flow in one direction, and can only be used between related processes. The kinship of process generally refers to the relationship between father and son. Anonymous pipes are generally used for communication between two different processes. When a process creates a pipeline and calls fork to create its own child process, the parent process closes the read pipeline and the child process closes the write pipeline. This provides a way for data flow between two processes.

The named pipeline is also a half duplex communication mode, but it allows communication between unrelated processes.

  1. Semaphore

Semaphore is a counter, which can be used to control the access of multiple threads to shared resources. It is not used to exchange a large number of data, but used for synchronization between multiple threads. It is often used as a locking mechanism to prevent other processes from accessing a resource when a process accesses it. Therefore, it is mainly used as a means of synchronization between processes and different threads in the same process

  1. signal

Signal is a more complex way of communication, used to inform the receiving process that an event has occurred

  1. Message queuing

Message queue is a linked list of messages, which is stored in the kernel and identified by message queue identifier. Message queue overcomes the disadvantages of less signal transmission information, the pipeline can only carry unformatted byte stream and limited buffer size. Message queue is a mechanism of sharing resources among different processes in UNIX. UNIX allows different processes to send formatted data streams to any process in the form of message queue. Msget can be used by any process with operation permission to control the message queue. By using message types, processes can read information in any order or prioritize messages

  1. Shared memory

Shared memory is to map a piece of memory that can be accessed by other processes. This piece of shared memory is created by one process, but can be accessed by multiple processes. Shared memory is the fastest IPC (inter process communication) mode, which is specially designed for the inefficiency of other inter process communication modes. It is often used with other communication mechanisms, such as semaphore, to achieve synchronization and communication between processes

  1. Socket: it can be used for communication between different processes

88. In master-slave replication, will the slave server read the data that the master server is rolling back? If the master database is successfully written and the slave server fails to write for some reasons, what will happen in the end? What if the master-slave key conflicts?

No; the master-slave data is inconsistent; normally, this scenario will not occur, depending on the situation, whether it can be repaired, and then recover the synchronization.

89. How many isolation levels are there for transactions? How is the isolation level of transactions implemented?

  • Read uncommitted
  • Read committed
  • Repeatable read
  • Serializable

90. What is B + tree? Please draw the structure of B + tree

91. For the character set in mysql, the client is inconsistent with the database. What should I do? What is the process of character conversion from string to display to interface in MySQL? The character set in the database is Latin1. Now you save the string of utf8 to the database table of Latin1 character set. Can you save the string of utf8? If you say it can survive, ask: can it recover? If so, how to recover?

92. Write a piece of code to find all subsets. For example, the subsets of [a, B, C] are {}, {a}, {B}, {C}, {AB}, {AC}, {ABC}

93, [‘a ‘= > 200,’ B ‘= > 100,’ C ‘= > 100], write a custom sorting function, descending by value, if the value is the same, press the key to sort

Bubble sort

94. Design a cache system, which can automatically delete long-term unused data on a regular basis or when the space is full, instead of traversing.

My answer at that time was to store the data in a linked list. When the cache hits, the cache will be moved to the head of the chain, and then the tail of the linked list will be cold data.

I remember where I saw the design before, but I forgot to connect it. Please know my friend’s name and paste the connection.

95, = = and = = = write the following output: “AA”1,”bb”0,1==”1″

  • ==Equal to, no need to compare data types
  • ===Congruent, need contrast type

false, true, true

96. A sorted array, cut it into two arrays from any position in the middle, and then exchange their positions and merge them. After merging, new array elements such as: 20, 21, 22, 25, 30, 1, 2, 3, 5, 6, 7, 8, 15, 18, 19, write a query function to find out whether a value exists.

97. Design a tree structure and write a function to traverse it

98. The difference between ‘$var’ and ‘$var’

The contents of double quotation marks can be interpreted and replaced, while the contents of single quotation marks are always considered as ordinary characters.

In a single quote string, even the backslash loses its extended meaning (except insert backslash and insert single quote). Therefore, you should use double quotation marks when you want to replace variables in a string and include escape sequences such as (newline character). Single quotation string can be used anywhere else, and it is faster to use single quotation string in script.

The difference between 99, self and static

Static: if the static methods and properties of the parent class are overridden in the subclass, the parent class will access the static methods of the subclass

Self: is a pointer within a class. No matter whether the subclass has overridden the methods and properties in the parent class, it points to the static methods and properties of the class

100, PHP coroutines and uses

101. Describe the mechanism of autoload

102. How many bytes are the field types in MySQL: smallint, int, bigint, datetime, varchar (8)

  • Smallint 2 bytes
  • Int 4 bytes
  • Bigint 8 bytes
  • Datetime 8 bytes
  • Varchar (8) 8 * 3 bytes

103. Which attributes uniquely determine a TCP connection

What is the difference between MyISAM and InnoDB? Why is MyISAM faster than InnoDB? What is the index data structure of MyISAM and InnoDB? What is the difference between InnoDB primary key index and non primary key index? What kind of data is stored in the index?

The difference is mainly in the storage structure and storage mode of data and index, as well as the support for transactions.

105. When the TCP connection is disconnected, will the timewait state appear at the end that initiated the breakup or the end that was broken up

Why does it take three handshakes to establish a TCP connection?

Reason: in order to deal with the problem of delayed repeated array in the network

example:
Suppose that the connection request message segment initiated by the client is not lost in the network, but is detained in a network node for a long time, resulting in delay in reaching the server. Originally, this is an invalid connection message, but after receiving this connection message, the server mistakenly thinks that the client has initiated a new connection, so it sends a confirmation message segment to the client. At this time, because there is no three handshakes of the connection, the client will not respond to the confirmation message of the server, and will not send data to the server. The server thinks that the connection has been established, and has been waiting for the data of the client, so this part of the network resources of the server is wasted.

Why does it take four handshakes to disconnect a TCP connection?

Because TCP connection is a full duplex network protocol, it allows both sides of the communication to send and receive data at the same time, and also allows the connection in both directions to be closed independently, so as to avoid the situation that the client sends data and sends fin to the server to close the connection, while the server does not send data to the client. So closing a TCP connection requires four handshakes, and closing a connection in one direction requires two handshakes of fin and ACK.

TIME_ The meaning of wait state

In TCP connection, when the fin message sent by the passive Closing Party (client in the figure) arrives, the passive closing party will send ack confirmation message and enter time_ Wait status, and wait for 2msl period( MSL:maximum segment life)。 There are two reasons for this:

If the passive Closing Party (the server in the figure) does not receive the ACK confirmation packet from the other party for a period of time, it will re send the fin packet. Therefore, the active closing party needs to stay in the waiting state to process the fin packet re sent by the other party. Otherwise, he will respond with an RST packet to the party who passively closes the connection, making the other party confused.

At time_ In wait state, the application is not allowed to establish a new connection on the current IP and port with the previous communicating client (the IP and port number of the client remain unchanged). In this way, we can avoid the new connection receiving the same IP and port connection remaining in the network packets. This is also time_ The reason why the wait time of wait state is set to 2msl to ensure that the TCP packets not received in both directions of the current connection on the network have disappeared.

106, awk all kinds of data analysis test is very much, to practice more, the topic is no longer written one by one

107. What are the data structures of set, ordered set, hyperlog and hash in redis

key value

108. Describe the whole processing process of a request arriving at nginx (what logic will nginx call), how to communicate with PHP, and what is the intermediate process, etc?

109, nginx and PHP FPM configuration, casually ask the meaning of various parameters

PHP FPM can be implemented by TCP socket and UNIX socket.

110. If you have a map, as shown in the following figure, “-” represents the ocean and “+” represents the land, use your best way to get the coordinates of the land.

--++----++--+++---
-++++----+++++++--
-+++----++++------
-----++------++++-
---++++++-----+++-
-----+++------+++-

For example, in the array above, 1 represents land and 0 represents ocean

[
    [0,0,1,1,0,0,0,1,1....],
    [0,1,1,1.....],
]

Write an algorithm to get the coordinates of all the land and put them together by blocks. For example, the coordinates of the first land in the upper left corner of the map are:

[
    [0,2],[0,3],
    [1,1],[1,2],[1,3],[1,4],
    [2,1],[2,2],[2,3]
]

111. What other cross domain methods do you know about the implementation principle of jsonp?

  1. JSONP
  2. Add response header to allow cross domain
  3. The way of agency

112. If a blog uses the referer method to detect the image anti-theft chain, how can it be cracked?

Curl sets the source address to cheat the other server to verify

113. Briefly describe the essence of MySQL query optimization, and give two examples

114. How to design a second kill system to ensure that the goods are not oversold?

115. What are the advantages of singleton mode? What are abstract classes? What other design patterns do you know?

Singleton pattern, also known as responsibility pattern, is used to create a single function access point in the program, which means that the instantiated object is unique.

All singleton patterns have at least three common elements:

  1. They must have a constructor and must be marked private
  2. They have a static member variable that holds instances of the class
  3. They have a common static method to access the instance

Singleton class can not be instantiated directly in other classes, it can only be instantiated by itself. Instead of creating a copy of the instance, it returns a reference to the instance stored inside the singleton class.

Abstract classes cannot be instantiated. Any class that has at least one method declared abstract must be declared abstract. A method defined as abstract only declares its calling method (parameter), but cannot define its specific function implementation.

  • Factory model
  • Adapter mode

More learning content can be accessedAs long as you can read it, your salary will go up a step

The above contents hope to help youA lot of PHPer always encounter some problems and bottlenecks when they are upgrading. They write too much business code and have no sense of direction. They don’t know where to start to improve. For this, I have sorted out some materials, including but not limited to:Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, tp6, laravel, yii2, redis, spool, swoft, Kafka, MySQL optimization, shell script, docker, microservice, nginxAnd so on many knowledge points, advanced dry goods need can be free to share with you, need can join mePHP Technology Exchange Group953224940

Advanced PHP monthly salary 30K > > > architect growth path [free access to videos and interview documents]