[Turn] About the ability of PHP programmers to solve problems

This topic has been discussed for a long time. Among the abilities that must be assessed in the interview, I personally think that problem-solving ability is the first, higher than the learning ability. The ability to solve problems can not only see the programmer's thinking ability, adaptability, exploration ability, etc., but also his experience. If you have poor problem solving skills, you will not pass the interview.

Here is an example, if I execute a PHP script, such as php test.php, the expectation is that it can return a string. But there is no information output after execution. How can I know what is wrong with the program at this time? Here, the problem-solving ability can be divided into 8 levels, and the later the expression ability is stronger.

 

Lv0 View PHP error message
The program does not achieve the expected effect, which proves that the code is wrong. Seeing the PHP error message is the first step. If you ignore the error message, it means that this person is not suitable for a professional programmer position. In some cases, the error display is turned off in the php.ini configuration, you need to modify php.ini to open the error message, or the error message is exported to the log file. In this case, you can directly tailf php_error.log to view the error message.

After getting the error message, directly locate the program code problem, or search on Google/Baidu to solve the problem.

Note: The way to turn on the error display is to

Display_errors / display_startup_errors in php.ini is set to On
error_reporting in php.ini is set to E_ALL
Set error_reporting(E_ALL) in PHP code

 

Lv1 there are multiple versions of php or php-cli and php-fpm load different configurations
There are multiple versions of php, know which php it is through which php, or add an absolute path to make a php version. Indicates that this PHPer has passed the 50% test of this level.

Another situation is that the execution situation obtained by php-cli and php-fpm is different. For example, the execution in the web browser is correct, and the execution under the cli is wrong. At this time, the php.ini loaded by the two environments may be different. Under cli, get which php.ini is loaded through php -i |grep php.ini. Under fpm, the absolute path of php.ini can be obtained through the phpinfo() function.

 

Lv2 var_dump/die print variable value information single step debugging
This is the usual method of program debugging, and it is also the most simple, rude and effective way to solve problems. The more advanced method is to use the Trace class/log class of PHP, and the fancy ones can be debugged in the IDE tool with the help of phpstorm+xdebug.

The Trace tool can also analyze the time-consuming of scripts and optimize the performance of PHP programs.

All of these three tests have passed, indicating that the programmer already has the problem-solving ability that a professional PHP programmer should have. As long as PHP programmers pass this level, they are enough to handle most situations and have no pressure on small and medium-sized websites.

 

Lv3 uses the strace tool to trace program execution
strace can be used to view the execution of system calls, use strace php test.php, or strace -p process ID. strace can help you see the essence through the phenomenon and grasp the process of program execution. This method is most commonly used in large websites and large companies. If you don't know strace, you can only say sorry here, we don't accept PHPers who don't know strace.

In fact, strace is also a test of the programmer's basics. If you don't know how to operate the operating system, and you don't understand the bottom layer at all, you will definitely not be able to use strace. Of course, strace cannot solve the infinite loop in PHP code. For example, if you find that the CPU of a php-fpm process is 100%, strace may not be able to solve it. Because strace looks at system calls, which are generally IO operations, since it is IO intensive, the CPU must not be 100%.

 

Lv4 uses the tcpdump tool to analyze the network communication process
tcpdump can capture the data communication process of the network card, and even the data content can be captured. Using tcpdump, you can see what the network communication process is like, when the TCP SYN3 handshake is initiated, when the FIN packet is sent, and when the RST packet is sent. This is a basic skill. If you don't understand tcpdump, it proves that you do not have the ability to solve network problems.

 

Lv5 statistical function call time and success rate
Use xhporf/xdebug to export the calling process of PHP requests, and then analyze the process and time-consuming of each function call. Be able to analyze the performance bottlenecks of PHP programs and find out the points that can be optimized.

Another call to network services, such as mysql query, curl, other API calls, etc., by recording the microtime at the beginning and end, whether the returned value is false, you can get whether the call is successful and how long it takes. If the data can be aggregated to sort out the call success rate, failure rate, and average delay, it proves that the programmer is sensitive to interface quality and has experience in large-scale website projects.

 

Lv6 gdb use
Gdb is a powerful tool for C/C++ debuggers. Only programmers with certain C/C++ skills can use gdb proficiently. The strace mentioned above cannot track the php program CPU100%, but gdb can track it. In addition, gdb can also solve the problem of core dump of php program.

The execution of PHP programs can be easily tracked through the process ID of gdb -p and tools such as .gdbinit zbacktrace of php-src. For example, the CPU100% above is often an infinite loop in the PHP program. After multiple viewings with gdb, you can roughly get the position of the infinite loop. Very few PHP programmers have the ability to solve problems with gdb. If you can use gdb to solve PHP problems, 100% of the PHPer can pass the interview and can get a high technical rating.

 

Lv7 View PHP kernel and extension source code
If you are familiar with the source code of the PHP kernel and extensions, you can also have the ability to solve the most complex memory errors in PHP programs. Such PHP programmers are rare. With the gdb tool and familiarity with PHP source code, you can view the opcode information, the memory of execute_data, and the status of global variables.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326613283&siteId=291194637