Eight Levels of PHP programmer's ability to solve problems _ PHP Tutorial

Source: Internet
Author: User
PHP programmers have eight levels of problem-solving capabilities. The eight levels of problem-solving ability of PHP programmers have been discussed. I personally think that the ability to solve problems ranks first in the interview, eight levels better than PHP programmers who can solve problems

I have been talking about this topic. I personally think that the ability to solve problems ranks first in the inevitably assessed ability during the interview, which is higher than the learning ability. The ability to solve the problem not only shows the programmer's thinking ability, adaptability ability, and exploration ability, but also shows his experience. If the problem solving capability is poor, you cannot pass the interview.

For example, if I run a PHP script, such as php test. php, a string is expected to be returned. But no information is output after execution. in this case, how can I know where the program is wrong? Here, we can divide the problem-solving capability into eight levels, and the more powerful it will be.

Lv0: View PHP error information

The program fails to achieve the expected results, proving that the code has gone wrong. it is the first step to view the PHP error message. If you ignore the error message directly, this person is not suitable for professional programmers. In some cases, php. the error display is disabled in the ini configuration. you need to modify the php. ini opens the error message, or the error message is exported to the log file. in this case, you can directly view the error information in tailf php_error.log.

After obtaining the error message, you can locate the program code problem or search for the problem on Google/Baidu to solve the problem.

Note: The error display method is

  • In php. ini, display_errors/display_startup_errors is set to On

  • In php. ini, error_reporting is set to E_ALL.

  • Set error_reporting (E_ALL) in PHP code)

Lv1 has multiple versions of php or php-cli and php-fpm to load different configurations.

There are multiple versions of php. you can use which php to see which PHP is used, or use an absolute path to develop the php version. This indicates that this PHPer has passed the 50% test at this level.

In another case, php-cli and php-fpm have different execution conditions. for example, if the execution is correct in a web browser, the execution in cli is wrong. This may be caused by different php. ini files loaded in two environments. Use php-I | grep php. ini in cli to obtain the php. ini file that is loaded. In fpm, the absolute path of php. ini can be obtained through the phpinfo () function.

Lv2 var_dump/die printing variable value information single-step debugging

This is a conventional program debugging method and the simplest and most effective solution to the problem. The advanced method is to use the PHP Trace class/log class. the fancy method can be Debug in the IDE tool using phpstorm + xdebug.

The Trace tool can also analyze the script Time and optimize the performance of PHP programs.

These three tests all pass, indicating that this programmer already has the ability of professional PHP programmers to solve problems. As long as PHP programmers pass this level, it is enough to handle most of the situations and there is no pressure on small and medium websites.

Lv3 use the strace tool to track program execution

Strace can be used to view the execution of system calls, using strace php test. php, or strace-p process ID. Strace helps you understand the process of program execution through phenomena. This method is most commonly used in large websites and large companies. If you do not know strace, we can only say sorry here. we do not accept PHPer without strace.

Strace is actually a test of the programmer's foundation. if you do not understand the operating system or the underlying layer, you certainly cannot use strace. Of course, strace cannot solve the endless loop in PHP code. For example, if you find a php-fpm process CPU100 %, strace may not be able to solve it. Because strace depends on system calls, it is generally an I/O operation. since it is IO intensive, the CPU cannot be 100%.

Lv4 uses tcpdump to analyze network communication process

Tcpdump can capture the data communication process of the NIC, and even the data content. Using tcpdump, you can see what the network communication process is like, how to initiate a TCP SYN3 handshake, when to send the FIN packet, and when to send the RST packet. This is a basic skill. if you do not understand tcpdump, it proves that you are not capable of solving network problems.

Lv5 counts the time consumption and success rate of function calls.

Use xhporf/xdebug to export the PHP request call process, and then analyze the process and time consumption of each function call. Analyzes the performance bottleneck of the PHP program and finds out the points that can be optimized.

Another network service call, such as mysql Query, curl, and other API calls, records the microtime at the start and end, and returns false to determine whether the call is successful and how much time is consumed. If you can summarize the data and sort out the call success rate, failure rate, and average latency, it proves that this programmer is sensitive to interface quality and has experience in large-scale website projects.

Use Lv6 gdb

Gdb is a powerful tool for C/C ++ to debug programs. programmers with C/C ++ skills can use gdb skillfully. The strace mentioned above cannot trace php program CPU100 %, while gdb can trace. In addition, gdb can also solve the core dump problem of the php program.

By using the gdb-p process ID and the. gdbinit zbacktrace tool of php-src, you can easily track the execution of PHP programs. As the above CPU100 % is often a life-and-death loop in the PHP program, gdb can obtain the location of an endless loop after multiple views. Few PHP programmers are capable of solving gdb problems. If you can use gdb to solve PHP problems, this PHPer can pass the interview and get a high technical rating.

Lv7 view PHP kernel and extended source code

If you are familiar with the PHP kernel and extended source code, and encounter the most complex memory errors in PHP programs, you can also have the ability to solve them. Such PHP programmers are rare. With the gdb tool and familiar with PHP source code, you can view opcode information, execute_data memory, and global variable status.

What level are you?

Author: http://rango.swoole.com/archives/340 @ Han Tianfeng-Rango

Http://www.bkjia.com/PHPjc/1051850.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1051850.htmlTechArticlePHP programmers ability to solve the problem of eight levels of this topic growth talk about, in the interview will inevitably assess the ability, I personally think that the ability to solve the problem is ranked first, than learning...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.