Summary of PHP advanced engineering interview questions

Time:2020-12-2

Summary of PHP advanced engineering interview questions (may 2018)

1. Give you four coordinate points to judge whether they can form a rectangle. For example, judge whether ([0,0], [0,1], [1,1], [1,0]) can form a rectangle.

In Pythagorean theorem, a rectangle is a quadrilateral with equal diagonals. As long as any three points are not on a straight line, choose any point, and find the square of the length from this point to the other three points. If the sum of the two short points is equal to the longest, then this is a rectangle.

2. Write a piece of code to determine whether there is a ring in the one-way linked list. If it is formed, please find out the entrance of the ring, that is, point P

/ *

3. Write a function to get all the pictures in an article and download it

function download_ images($article_ url = '', $image_ path = 'tmp'){

4. Get the IP address of the current client and determine whether it is in (111.111.111.111222.222.222.222)

If you are not using a proxy server:

$ip = $_SERVER[‘REMOTE_ADDR’];

Use transparent proxy

$ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];

Reference articles

https://www.cnblogs.com/rendd/p/6183094.ht…

5. Log of nginx_ Format configuration is as follows:

log_format main ‘remoteaddr−remote_user [timelocal]"request”’ 
‘statusbody_bytes_sent “httpreferer"″"http_user_agent” “upstreamresponsetime""request_time” “http_x_forwarded_for"';

From today’s nginx log file access.log Chinese:

  • a. List “request”_ The top 20 lines of “time”?
  • b. List 20 URLs with more visits at 10 am?

6. What is a CSRF attack? XSS attack? How to prevent it?

CSRF: Cross Site Request Forgery can be prevented by judging the source and adding token.

XSS: cross site scripting attacks, which can be prevented by escaping and filtering content, and CSP

7. In the application, we often encounter the situation that 10 pieces of data are randomly fetched from the user table to display. Briefly describe how you realize this function.

SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 1;

Reference articles:

https://www.cnblogs.com/riasky/p/3367558.h…

http://www.jb51.net/article/48801.htm

8. Draw 5 cards randomly from playing cards, judge whether it is a straight, that is, the five cards are continuous

There is a key point in this question, playing cards, 1-13 can’t be more. It’s very simple. Use PHP to do, define an array to store 1 to 13, take out one, empty one, and finally see whether the five empty are continuous. In this case, the order of extraction is not considered.

9. How to find the first common node of two intersecting unidirectional linked lists

Thought:

  1. If two linked lists intersect, the nodes behind are the same from the intersection point, that is, the last node must be the same;
  2. Traverse the two lists from the beginning to the end, and record the length of the list. When the tail nodes of the two are different, the two must not intersect;
  3. If the length of a is La and B is lb, if LA > lb, then the la-lb before a will be skipped first

    If two unidirectional lists have a common node, that is to say, two lists start from a node, their M_ Pnext points to the same node. But because it is a node of one-way linked list, each node has only one M_ Therefore, starting from the first common node, all of them are coincident, and there is no possibility of bifurcation. Therefore, the topological shape of two partially overlapped linked lists with common nodes looks like a Y, but not like X.

reference:

https://blog.csdn.net/wcyoot/article/detai…

https://blog.csdn.net/Lieacui/article/deta…

10. If there are two arrays [1,2,5,11,32,15,77] and [99,32,15,77] in LCS, we can find the number they have in common and write the code with the best time complexity_ There is a hole here, so we need to study dynamic programming.

11. The principle of memory allocation and multithreading in Linux

12. The difference between primary key and unique index in MySQL

Primary key: must not have null value. Unique index: can have null value

reference resources:https://www.cnblogs.com/lonelyxmas/p/45946…

13. The main differences between HTTP and HTTPS

The key is s. In short, after the connection is established, the SSL certificate should be sent first. With the public key and private key, the decryption can be performed.

reference resources:https://www.cnblogs.com/zyl-Tara/p/7079696…

14. HTTP status code and its meaning

  • 200 request has been successful. The response header or data body expected by the request will be returned with this response.
  • 301 the requested resource has been permanently moved to the new location.
  • 302 the requested resource now temporarily responds to the request from a different URI.
  • The current request cannot be understood by the server due to semantic error. 2. Error in request parameters.
  • 401 the current request requires user authentication.
  • The 403 server understood the request, but refused to execute it.
  • 404 request failed. The requested resource was not found on the server.
  • The 500 server encountered an unexpected condition and could not complete the processing of the request. It will appear when the program code fails.
  • The 501 server does not support a function required by the current request. The requested method was not recognized.
  • 502 when a server working as a gateway or proxy attempts to execute a request, it receives an invalid response from the upstream server.
  • 503 the server is currently unable to process requests due to temporary server maintenance or overload.

reference resources:http://tool.oschina.net/commons?type=5

15. How to check the usage of system resources in Linux

top、htop、free、uptime

16. What is the principle of SQL injection? How to prevent SQL injection

Principle: first, there is a problem with SQL itself (this is not the main problem). Secondly, the SQL you write is very problematic (this is the most important one)

Prevention: first, never trust anything entered by users. Second, precompiling. Today’s frameworks generally have SQL filtering.

17. Isset (null) isset (false) empty (null) empty (false) output

Introduction to PHP, the difference between isset and empty

They are false, true, true, true

18. The method of optimizing MySQL

First, if the data exceeds a certain amount or volume, please split the table and divide it vertically or horizontally

Second, there must be an auto increment primary key. It is the fastest way to query data through auto increment primary key.

Third, common query fields are used to establish a joint index. When writing SQL, you must follow the leftmost principle and use this index.

Fourth, don’t put logical operations in SQL. The implication is, don’t write too complex SQL, you can write complex SQL, you can certainly achieve it through PHP.

reference resources:https://cloud.tencent.com/developer/articl…

19. What are the transactions in the database?

A transaction is an ordered set of database operations as a unit. If all operations in the group succeed, the transaction is considered successful, and even if only one operation fails, the transaction does not succeed. If all operations are completed,

The transaction is committed, and its modification will affect all other database processes. If an operation fails, the transaction will be rolled back and the influence of the transaction will be cancelled.

20. Write a function to extract the file extension from a standard URL as efficiently as possible

It’s best to write regular. I won’t be regular anyway. I need to use Baidu.

21. The parameter is an array of multiple dates and times, and the time closest to the current time is returned

Traverse the array, find the current time difference, and the first comparison, less than the first exchange position. Finally, take the first one.

22、echo、print、print_ The difference of R

Put these three together, the answer is: print_ R is a function, echo and print are structural languages.

As for their specific differences, please refer to:https://www.cnblogs.com/xiaotaoing/p/66873…

23. What are the keys and meanings in the header of HTTP protocol

This problem is very difficult. I won’t be clear for a while and a half. If you have done PHP restful interface development, but also stepped on this pit, it should be able to answer several commonly used keys.

reference resources:https://blog.csdn.net/u014175572/article/d…

24. Traversal code before, in and after binary tree

1. Sequence traversal

2. Preorder traversal

3. Middle order traversal

4. Postorder traversal

reference resources:https://blog.csdn.net/wk199351/article/det…

25. What is the difference between PHP array and C language array structure?

But from PHP, the test is the implementation of PHP array. In fact, hash / table is an array of hash arrays. The advantage is that the query efficiency is very high, traversal is very convenient, the disadvantage is that it takes up more memory. (it’s still the idea of exchanging space for time. After all, the memory is not valuable now.)

The array of C language is the sequence of fixed length and fixed type.

26. How to implement redis’s jump table

Skip list is an ordered data structure. It can access nodes quickly by maintaining multiple pointers to other nodes in each node.

reference resources:https://blog.csdn.net/universe_ant/article…

27. What is hash? How to store data after hash conflict?

28. The difference between clustered index and clustered index?

29. How does B + tree search

30. What is the difference between array and hash?

31. Write a function to judge whether the following extension is closed. The left and right symmetry is closed: ((()),) (()), (())), ((((()), (())), ((((()), (()))

32. Find the non duplicate values in the array [1,2,3,3,2,1,5]

In the ordinary way, it must be easy.

What is your time complexity? In some cases, you write an algorithm, and then the interviewer will ask you to write the time complexity expression of your algorithm

34. How to implement this weak type variable in PHP?

There is only one structure in the eight types of PHP.

reference resources:https://blog.csdn.net/ohmygirl/article/det…

35. In the process of HTTP communication, is the client or the server actively disconnected?

Three handshakes and four waves, and the state of each step.

It’s better to answer this question comprehensively in one step. Generally, there are clients telling the server that I have finished sending things. Can I disconnect. However, if the client sends the fin and the server does not reply, it will try again until the timeout period is exceeded. The same is true for the server. If the time is exceeded, the server will be broken.

36. What are the ways to initiate HTTP requests in PHP? What’s the difference between them?

  1. GET
  2. POST
  3. HEAD
  4. PUT
  5. DELETE
  6. OPTIONS
  7. TRACE
  8. CONNECT

37. There is a binary tree. Write code to find the shortest path from the root node to the flag node and print it out. There are multiple flag nodes. For example, 6 and 14 in the tree below are flag nodes. Please write code to print the paths 8, 3, 6 and 8, 10 and 14

Summary of PHP advanced engineering interview questions

A typical binary search tree. Basic problems of university data structure.

reference resources:https://blog.csdn.net/BaiHuaXiu123/article…

38. There are two file files, the size of which is more than 1G, one line of data, and each line of data is no more than 500 bytes. Some contents of the two files are identical. Please write code to find the same line and write it to the new file. The maximum allowed inner space of PHP is 255m.

The file is divided into several small files, and the hash value is calculated according to the content, and distributed to different files.

39. Please write at least two PHP functions that support callback processing, and implement a PHP function supporting callback yourself

array_map,array_filter, array_walk

40. Please write at least two methods (code or idea) to get all the files in the specified folder.

The core method is scandir, and the core idea is recursion.

41. Please write three methods or functions for intercepting the suffix of file name (both PHP native function and self implemented function can be used)

echo substr(strrchr($file, '.'), 1);

echo substr($file, strrpos($file, '.')+1);

$arr=explode('.', $file);
echo $arr[count($arr)-1];

$arr=explode('.', $file);
echo end($arr);

echo strrev(explode('.', strrev($file))[0]);

echo pathinfo($file)['extension'];

echo pathinfo($file, PATHINFO_EXTENSION);

42. How does PHP issue cookies for clients without using the cookie function. For distributed systems, how to save the session value.

This is a bit of a detour. The basic knowledge of cook and session. The server notifies the client to save the cookie through the set cookie command.

It can be implemented by using the header function according to the rules of domain path expiration time.

Distributed system session, centralized processing. According to our company’s architecture, in order to achieve high availability and high disaster recovery, we provide a distributed signature verification service. For details, take a look at redis’s distributed service architecture.

43. Please use shell to count the most visited URL addresses in nginx logs within 5 minutes, and what are the corresponding IP addresses?

44. Write a shell script to backup the specified MySQL database (such as test) to the specified folder and package it, delete the backup 30 days ago, and then push the new backup to the remote server to complete the email notification.

45. The difference between InnoDB and MyISAM engine in MySQL database

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

reference resources:https://blog.csdn.net/chajinglong/article/…

46. What kind of process does it take from the user to enter the website address in the browser and press enter to see the complete meeting.

Introduction. There is a big hole in this question. The interviewer may start with this question and ask you a lot of questions.

Take PHP as an example: usually, the simplest answer is to find the nearest DNS service from the user’s computer, and then resolve to the corresponding IP address. Then both parties start HTTP connection, and then send the request information. After receiving the request information, the server starts to prepare the response information. In the middle, it is transferred to frstcgi (php-fpm) through nginx, Then PHP starts to parse the framework, parse the request header, find the corresponding API, query the database, assemble HTML, assemble HTML, and then return it to the user. The user gets the returned data, the browser starts to render the page, and JS starts to load.

47. How to analyze the performance of an SQL statement.

Please Baidu for details. (performance analysis statements are rarely used. In the design of MySQL tables, some fields should be redundant as much as possible to avoid processing a large number of logical operations in MySQL. We do PHP service development, MySQL statements can be simple as far as possible. The logical operation can be done in PHP.)

48. Ping a server fails to Ping. Which command is used to track the routing packets?

linux:traceroute,windows:tracert

49、$a=[0,1,2,3]; $b=[1,2,3,4,5]; $a+=$b; var_ What is dump $a equal to?

Basic issues. The essence is to test the structure and characteristics of PHP array.

The result is 01235. PHP index with a number and string index is still very different

reference resources:http://www.jb51.net/article/38593.htm

50、$a=[1,2,3]; foreach($a as &$v){} foreach($a as $v){} var_ How much is dump $a;

122

There is a pit here. After foreach is finished, the last assignment is retained.

After the first foreach, the last element in the array becomes a reference, and the reference variable $V continues to exist and points to the last element of the array. For the second traversal, because the traversal variable name is $V, it means that the value of this traversal will be changed to the value of the last element until the last element (reference element) is traversed. At this time, the last element of the array has been modified to the value of the previous element, and the last assignment is I = = myself. So the last one is equal to the penultimate

Blog: [PHP – ray] ray of foreach and reference

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

Idea: producer and consumer model. This question also does not say other states, such as database data will increase in real time? Is there any other service reading or writing to each wallet in redis. Something. When database and redis are put together, either data consistency or lock occurs, 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?

I don’t know. I haven’t used it. Why is it so designed? Deliberately make yourself unhappy?

53. What are the process signals in Linux?

Kill – L is rarely used

54. The underlying implementation of redis

When the interviewer asks you this way, you ask him, is the design of the field the underlying implementation you want? Memory allocation management? Network model? Data synchronization? Or distributed implementation? Tips: an interview is a game between two people. The interviewer gives a question that is not clearly described, and we don’t have to answer it. Let him explain the problem clearly and then think about how to reply)

reference resources:https://cloud.tencent.com/developer/articl…

This article should be read several times.

55. Asynchronous model

It is the IO asynchronous model. It is also an asynchronous request model like Ajax. It’s very different.

reference resources:https://cloud.tencent.com/developer/articl…

Goudong a risk control research and development must test.

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

A little rough way ini_ set(‘memory_ Limit ‘,’ – 1 ‘); first, the current memory limit is lifted, and then the statistics are made row by line. It will be very long.

If there is a better way, please leave a message.

There are 5.7 billion orders for drivers

Don’t get hit. Don’t use common ideas to deal with it. No matter how you optimize a billion data, it will kill you to sum the whole table.

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

58. Design a wechat red packet function

No. In fact, the topic 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 QPS of the last 5 seconds are counted in the file and displayed in the following format: 01 1000 (difficulty in 01 serial number)

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

reference resources:https://blog.csdn.net/dong_007_007/article…

60. Why is the performance of php7 improved so much

No coercion, direct reference:http://www.laruence.com/php-internal

Bird brother’s articles should be read more and more.

61. Traverse a multidimensional array

Recursion. array_ Map passes in a callback function.

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

substr_count();

63. There is a 1g file with a word in each line. The word size is no more than 16 bytes. The memory limit is 1m. Return 100 words with the highest frequency

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

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

Reference: question 64.

Summary of ten interview questions and ten methods for massive data processing

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

65. PHP process model, how does PHP support multiple concurrency

The daemons model (you need to know the various configurations of PHP FPM)

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

66. How can nginx support multiple concurrency

This is not clear in a few words.

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

67. PHP FPM configuration meaning, FPM daemonize mode

There are not many PHP FPM configurations, even fewer commonly used ones.

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

Static - the number of child processes is fixed( pm.max_ children)

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

Reference: essential cap principle for distributed architecture design.

69. If one of the two MySQL servers is hung up, how can the business end switch senselessly and ensure that the data of the platform server is consistent under normal circumstances

If it is 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 now on the normal state machine. Pull up the standby machine of the good machine and use it as the main engine.

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 reject it, and how many write operations are you doing per second. According to the Megascale table, the write efficiency is 1000 per second. The normal design is distributed on two machines, each with 500. This level of data synchronization, the probability of differences can be ignored. If there is a problem with one, the other can resist.

(in normal operation, it is still necessary to stop writing first, and then switch to write when the data is consistent. Our company makes these switches around 4.00 am, 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 very difficult to answer. It’s too broad. We haven’t asked such questions for a long time.

Reference: illustrated HTTP written by Japanese

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 came across this hole in my internship.

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

In the case of small random number interval, there is no big efficiency gap. However, Rand is more likely than MT to have repeat numbers_ Rand is much higher.

73. How to implement MySQL transaction isolation

Through various row locks, table locks, optimistic locks, pessimistic locks, exclusive locks.

74. How to implement MySQL lock

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 and 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 in 24 hours. Ask: with at least a few mice, we can find out which bottle of water is toxic in 24 hours.

Four

Binary problem. Schrodinger’s mouse.

A mouse has two states, dead or alive, corresponding to 01. If the number of mice is a, then there are 2 ^ a > = 10; a = 4;

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

No. The first mouse drank all the ones: 13579, the second one drank the ten ones, the third and the hundredths were one, and the fourth drank the thousand ones.

24 hours later, the dead is 1 and the living is 0. Stand up in the order of mice If the first and the third died, it would be 0101, that is, there was a problem with 5.

77. How does redis synchronize, how to synchronize, what to do with synchronous rollback, and what to do with data exceptions. At the same time, you 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 a memory snapshot.

After the slave is started and connected to the master, it will actively send a sync command (first, the master will start a background process to save the data snapshot to the file [RDB file]. The master will send a sync command to the slave

The ping command is used to determine the survival status of the slave. When the slave is alive, the master will send the data file to the slave and send all write commands to the slave).

Slave first saves the data file locally and then loads the data into memory.

In case of the first link or reconnection after failure, the survival state of the slave will be judged first, and then all the data will be synchronized, and then only the write operation of the master will be synchronized (the command will be sent to the slave)

Question:

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

The advantages of redis master-slave replication are as follows:

(1) In a redis cluster, the master is responsible for writing requests and the slave is responsible for reading requests. On the one hand, by distributing the read requests to other machines, the pressure on the master server is greatly reduced. On the other hand, the slave focuses on providing

Read service improves response and read speed.

(2) In a redis cluster, if the master is down, the slave can intervene and replace the master. Therefore, the entire redis service is not unable to provide services, which makes the whole redis service secure enough.

(3) Adding slave machines horizontally can improve performance

reference resources:

78. How to solve cross domain problem

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

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

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

(2) Scalability: both have good scalability;

(3) Coding difficulty: relatively speaking, the encoding of JSON is relatively easy;

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

(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 and process, and better data interaction;

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

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

reference resources:https://blog.csdn.net/java19880223/article…

80. Trait priority

In trait inheritance, the order of precedence is: members from the current class override the methods of the trait, while trait covers the inherited methods

81. A refers to B, and an error is reported. If the class in C is repeatedly defined, what will happen to the circular reference

82. The salary of the following employee 3 is greater than that of his / her supervisor. An SQL query finds the supervisor whose salary is lower than that of his / her subordinates

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 determine whether this 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?

https://www.cnblogs.com/huanyou/p/5775965….

Write a program to find the longest substring

http://www.jb51.net/article/128449.htm

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

Check the nginx log to see if 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 inter process communication modes

1) Pipeline

Pipes are divided into well-known pipes and nameless pipes

Ring pipe is a half duplex communication mode, data can only flow in one direction, and can only be used between processes with kinship. Process affinity generally refers to parent-child relationship. Anonymous pipes are generally used for communication between two different processes. When a process creates a pipe and calls fork to create its own child process, the parent process closes the read pipe side and the child process closes the write pipe side. This provides a way of data flow between two processes.

Well known pipes are also a half duplex way of communication, but they allow communication between unrelated processes.

2) 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 the resource. Therefore, it is mainly used as a means of synchronization between processes and between different threads in the same process

3) Signal

Signal is a kind of complex communication mode, which is used to inform the receiving process that an event has occurred

4) 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 characteristics of less signal transmission information, pipeline can only carry unformatted byte stream and limited buffer size. Message queue is a mechanism of sharing resources between different processes in UNIX, UNIX allows different processes to send formatted data stream to any process in the form of message queue. Processes with operation authority on message queue can use msget to control message queue operation. By using message type, process can read information in any order or arrange priority order for messages

5) Shared memory

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

6) Socket: can be used for communication between different processes

88. Master slave replication. Will the slave server read the data being rolled back by the master server? If the master database is successfully written and the slave server fails to write for some reasons, what will happen in the end? What about master slave replication if key conflicts?

No; the master-slave data is inconsistent; normally, this scenario will not occur. Depending on the situation, whether it can be repaired, restore to the previous point in time, and then recover the synchronization.

89. How many isolation levels do transactions have? How is the isolation level of transactions implemented?

  • Read uncommitted
  • Read committed
  • Repeatable read
  • Serializable

https://www.cnblogs.com/huanongying/p/7021…

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

https://blog.csdn.net/qq_23217629/article/…

91. What should I do if the character set in MySQL is inconsistent with the database? 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 in it? If you say it can be saved, ask: can it be restored? If so, how can it be recovered?

92. Write a piece of code and find all the 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 user-defined sorting function in descending order. If the values are the same, press the key to sort

Bubble sort

94. Design a cache system, which can automatically delete the data that has not been used for a long time on a regular basis or when the space is full, instead of traversing.

My answer at that time was to use the linked list to store. If the cache hit, the cache would be moved to the chain header, and then the tail of the list would be cold data.

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

Write the following output: “AA” = = 1, “BB” = = 0, 1 = = 1

  • ==Equal to, do not need to compare data types
  • ===Congruent, need to compare type

false, true, true

96. A sorted array, cut it from any middle position into two arrays, 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 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 regarded as ordinary characters.

Even the backslash loses its extended meaning in a single quote string (except for the insertion of a backslash and the insertion of a single quotation mark). Therefore, you should use double quotation marks when you want to substitute variables and include escape sequences such as line breaks in a string. Single quote strings can be used anywhere else, and it is faster to use them in scripts.

99. The difference between self and static

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

Self: refers to the pointer in the class. Whether the subclass has overridden the methods and properties in the parent class, it points to the static methods and properties of this class

100. PHP’s coroutines and uses

http://www.laruence.com/2015/05/28/3038.ht…

https://blog.csdn.net/gavin_new/article/de…

101. Describe the mechanism of autoload

https://blog.csdn.net/zhihua_w/article/det…

102. In mysql, the field type takes up several bytes: smallint, int, bigint, datetime, varchar (8)

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

http://www.jb51.net/article/55853.htm

103. Which attributes uniquely determine a TCP connection

104. 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 is the data stored on the index?

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

reference resources:https://blog.csdn.net/chajinglong/article/…

105. When the TCP connection is disconnected, will the timewait state appear at the end of the initiating breakup or the broken up end

Why three handshakes are needed to establish a TCP connection?

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

example:

It is assumed that the connection request segment initiated by the client is not lost in the network, but remains in a certain 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 an acknowledgement message to the client. At this time, because there is no connection handshake for three times, the client will not respond to the server’s confirmation message and will not send data to the server. The server thinks that the connection has been established and is waiting for the client’s data all the time. As a result, this part of the network resources of the server will be 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 simultaneous communication to receive 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 the fin to the server to close the connection after sending the data to the client, and the server still has the situation that the data sent to the client has not been sent. Therefore, to close a TCP connection, four handshakes are required, and two handshakes of fin and ACK are required to close a connection in one direction each time.

TIME_ Meaning of wait state

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

The party who passively closes the connection (the server in the figure) will resend the fin packet if it does not receive the ACK confirmation packet from the other party within a period of time. Therefore, the party who actively closes the connection needs to stay in the waiting state to process the fin packets sent again by the other party. Otherwise, he will respond to a RST packet to the party who passively closes the connection, making the other party puzzled.

In time_ In the wait state, the application is not allowed to establish a new connection with the previously communicating client (the IP and port number of this client remain unchanged) on the current IP and port. In this way, it 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 the wait state is set to 2msl to ensure that all TCP messages that have not been received in both directions of the current connection on the network have disappeared.

https://www.cnblogs.com/zhoudayang/p/60122…

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 sets, ordered sets, hyperlog, and hash in redis

key value

108. Describe: the whole processing process of a request arriving at nginx (what logic does nginx call itself), how to communicate with PHP, what kind of process is in the middle, and so on?

https://www.jianshu.com/p/df89b530db89

https://blog.csdn.net/xiajun07061225/artic…

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

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

https://blog.csdn.net/koastal/article/deta…

110. If you have a map, as shown in the following figure, “-” represents the ocean and “+” represents land. Take out the coordinates of the land in the way you are best at.

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

For example, the above figure is represented in the array as follows: 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 block. 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 approaches do you know about jsonp?

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

112. How to crack a blog’s anti-theft chain by judging the referer mode?

Curl sets the source address to cheat the other server’s authentication

113. 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?

https://blog.csdn.net/zhoudaxia/article/de…

115. What are the advantages of singleton? What is an abstract class? What other design patterns do you know?

Singleton pattern, also known as responsibility pattern, is used to create a single function access point in a program. In other words, 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

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

Abstract classes cannot be instantiated. If at least one method in a class is declared abstract, then the class must be declared abstract. A method defined as abstract only declares its calling mode (parameter), but cannot define its specific function implementation.

https://www.cnblogs.com/kangxl/p/6347179.h…

Factory model

Adapter mode

116. In the fight against landlords, how much more likely are landlords to get Wang’s bombing than peasants?

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint

Recommended Today

Elasticsearch database | elasticsearch-7.5.0 application foundation actual combat

Elasticsearch is a distributed and restful search and data analysis engine. ——Elastic stack website On elasticsearch’s “love and hate”“ Perhaps when it comes to search servers, most people will think of Solr, elasticsearch, and even the self-development of large domestic manufacturers. With the advent of the era of artificial intelligence and big data, a series […]