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

Time:2021-3-3

51. The user ID is stored in the database and there are many lines of fee deduction. The user’s wallet is stored in redis. Now we need to write a script to synchronize the fee deduction records in the database to redis and execute it every five minutes. What should we consider?

Thinking: producer and consumer model. This question does not mention other states, such as will the data in the database increase in real time? Is there any other service reading or writing in each wallet in redis. I don’t know. Database and redis together, either test data consistency, or test lock, resulting in reduced efficiency.

52. MySQL master-slave server. If the master server is InnoDB engine and the slave server is MyISAM engine, what problems will be encountered in practical application?

53. What are the process signals in Linux?

54. The underlying implementation of redis

When the interviewer asks you like this, you ask him, is the underlying implementation you want field design? Memory allocation management? Network model? Data synchronization? Or distributed implementation? Tips: an interview is a game between two people. There is no need for us to answer a question that is not clearly described by the interviewer. Let him make the question clear and think about how to reply

55. Asynchronous model

Ask clearly is Io asynchronous model. Or an asynchronous request model like Ajax. It’s very different.

56, 10g file, use PHP to check its line number

A more crude way_ set (‘memory_ Limit ‘,’ – 1 ‘); first remove the current memory limit, and then directly count line by line. It’s going to be a long time.

There is a better way, please leave a message.

57. If there are 1000 drivers with 1 billion orders, please take out the top 20 drivers

(TIPS) don’t get caught. Don’t use common ideas to deal with the data. No matter how you optimize the data of 1 billion or how you sum up the whole table, you will be dead.

We solve this problem in terms of design. There are only a thousand drivers. We can do a simple hash, sub database sub table, and% remainder. Make sure that the 1000 drivers are divided into 1000 watches, and each driver has his own watch. The engine uses mysaim to find the total number of data in the table, which is very efficient. It can traverse 1000 tables and find the maximum number of the top 20.

58. Design a wechat red envelope function

No. In fact, the title is not clear. If you have done WeChat official account development, you know that the XML data structure of WeChat event model should be well done.

59. According to access.log The file counts the QPS of the last 5 seconds and displays them in the following format, 01 1000 (the difficulty is 01 serial number)

tail -f access.log | awk -F '[' '{print $2}' | awk '{print $1}' | uniq -c

60. Why is php7 performance improved so much

Do not force, direct reference:http://www.laruence.com/php-internal

Bird brother’s article should be read more, read more.

61. Traverse a multidimensional array

Recursion. array_ Map passes in a callback function.

62. There is such a string abcdefgkbcdefab… Of random length. Write a function to find the number of times BCDE appears in this string

substr_count();

63. There is a 1g file, in which each line is a word, and the size of the word does not exceed 16 bytes. The memory limit is 1m. Return the most frequent 100 words

There are too many methods, but each has its own problems.

I might just do it with hash mapping. Others, No.

Reference: question 64.

64. Ten interview questions and ten methods of mass data processing

https://blog.csdn.net/v_JULY_v/article/details/6279498

65. PHP process model, how does PHP support multiple concurrent processes

Daemons model (need to know the configuration of PHP FPM)

reference resources:https://www.jianshu.com/p/542935a3bfa8

66. How can nginx support multiple concurrent processes

This is not clear in a few words.

reference resources:https://www.zhihu.com/question/22062795

67, PHP FPM configuration meaning, FPM daemonize mode

PHP FPM configuration is not much, less commonly used.

reference resources:http://www.4wei.cn/archives/1002061

Static - the number of child processes is fixed( pm.max_ children)
Ondemand - processes are generated only when there is a demand (when requested, as opposed to dynamic, pm.start_ Servers starts when the service starts
Dynamic - the number of child processes is set dynamically based on the following configuration: pm.max_ children, pm.start_ servers, pm.min_ spare_ servers, pm.max_ spare_ servers

68. Let you realize a simple architecture and keep it highly available. There are two interfaces, one is to upload a text, the other is to get the uploaded content. How do you design it? In order to avoid single room failure, at the same time, make the code level insensitive.

69. When one of the two MySQL servers is down, how to make the business end switch without feeling and ensure that the data of the platform server is consistent under normal circumstances

If it’s not a core business, stop writing first, pull up the standby machine, check the logs of the two machines, make data compensation, and start writing.

If it is a core business, all write operations are in normal state. Pull up the standby machine of the good machine and act as the host.

All of the above are emergency operations. In fact, the disaster recovery design of database is much more complex.

If the interviewer asks you what to do if the data of the standby machine is inconsistent, you should bravely connect it back. How many write operations do you have per second. According to the million level table, the write efficiency of 1000 per second, the normal design is distributed on two machines, each 500. This level of data synchronization, the probability of differences can be ignored. If one goes wrong, the other can resist.

(for normal operation, stop writing first, wait for data consistency, switch and start writing. Our company makes these switches around 4.00 a.m., and there are only a dozen write operations per second in the core business. The delay is less than 20 seconds.

70. Specific definition of HTTP protocol

This kind of question is difficult to answer. It’s too broad. We haven’t asked this kind of question for a long time.

71. What is lock and how to solve the problem of lock

Computer theory, producer consumer model, banker model, can solve the problem of lock.

72, Rand and Mt_ The difference between Rand

I met this pit during my internship.

It’s Mt_ Rand is four times faster than Rand.

In the case of small random number interval, there is no big efficiency gap. But the probability of repeat number is higher in Rand than in Mt_ Rand is much higher.

73. How to achieve MySQL transaction isolation

Through all kinds of row lock, table lock, optimistic lock, pessimistic lock and exclusive lock.

74. How to realize the lock of MySQL

https://blog.csdn.net/alexdamiao/article/d

https://www.cnblogs.com/luyucheng/p/629775

https://blog.csdn.net/tangkund3218/article

75. Symmetric encryption and asymmetric encryption

Symmetric encryption: we share a secret key, you encrypt, I decrypt.

Asymmetric encryption: I give you a public key. After you encrypt, I can also have my private key to decrypt the ciphertext. But you don’t have my private key.

Extension: elliptic encryption algorithm.

76, 10 bottles of water, one of which is poisonous. After drinking the poisonous water, the mice will die 24 hours later. Q: at least a few mice can find out which bottle of water is poisonous 24 hours later.

Four

Binary problem. Schrodinger’s mouse.

A mouse has two states, life and death, corresponding to 01. Suppose that the number of mice is a, then there are 2 ^ a > = 10; a = 4;

The idea is very simple, 10 bottles of medicine number: 0,1,10,11… 1001;

I don’t drink it. The first mouse drank all the 1-digit drinks: 13579, the second mouse drank 10-digit drinks: 1, the third mouse and 100 digit drinks: 1, and the fourth mouse drank 1000 digit drinks: 1.

24 hours later, look at the dead is 1, alive is 0. Stand up in the order of mice If the first one and the third one die, it’s 0101, that’s 5.

77. How does redis synchronize, how to synchronize, what to do with synchronization rollback, and what to do with data exceptions? At the same time, it will ask MySQL about the synchronization mode and related exceptions

Simple principle of master slave synchronization in redis cluster

The replication function of redis is based on the persistence strategy of memory snapshot. That is to say, no matter what your persistence strategy is, as long as the replication function of redis is used, there will be memory snapshot.

After slave starts and connects to master, it will send a sync command (first, master will start a background process to save the data snapshot to a file [RDB file] and master will send a sync command to slave

When the slave is alive, the master will send the data file to slave and send all write commands to slave.

Slave will first save the data file locally, and then load the data into memory.

When connecting for the first time or reconnecting after failure, it will first determine the survival state of slave, synchronize all data, and then only synchronize the master write operation (send the command to slave)

Question:

When the master synchronizes data, if there is a large amount of data and the master only enables a background process to synchronize multiple slaves, the master will have too much pressure and the recovery time of slave will be very slow!

  • Advantages of redis master-slave replication

(1) In a redis cluster, the master is responsible for writing requests, while slave is responsible for reading requests. On the one hand, by dispersing the reading requests to other machines, the pressure of the master server is greatly reduced. On the other hand, slave focuses on providing services
Read service improves response and read speed.

(2) In a redis cluster, if the Master goes down, slave can intervene and replace the location of the master, so it is not impossible for the whole redis service to provide services, which makes the whole redis service secure enough.

(3) Adding slave machines horizontally improves performance

78. How to solve cross domain problems

  • JSONP
  • Add response header to allow cross domain
  • The way of agency

79. What are the advantages and disadvantages of JSON and XML

(1) Readability: basically the same, XML readability is better;

(2) Scalability: all of them have good scalability;

(3) Coding difficulty: relatively speaking, JSON coding is relatively easy;

(4) Decoding difficulty: the decoding difficulty of JSON is basically zero, and XML needs to consider the child node and parent node;

(5) Data volume: compared with XML, JSON has smaller data volume and faster transmission speed;

(6) Data interaction: the interaction between JSON and JavaScript is more convenient, easier to parse, better data interaction;

(7) Data Description: XML is better for data description;

(8) Transmission speed: JSON is much faster than XML.

80. Train priority
In trait inheritance, the order of priority is: members from the current class override the methods of trait, while trait override the inherited methods


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]