PHP programmers can solve eight major problems

Source: Internet
Author: User
: This article mainly introduces the PHP programmer's ability to solve eight major problems. For more information about PHP tutorials, see. 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 shows the programmer's ThinkingHis experience can also be seen. 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, locate the program code problem, or go to Google/BaiduSearch 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 consumption for PHP programsPerformance Optimization.

All three tests have passed, indicating that this programmer is already professional.PHP programmersThe problem solving capability should be available.PHP programmersAs long as this level is passed, 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's death in PHP codeLoopIt cannot be solved. 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. Ability to analyze PHP programsPerformance bottleneckTo find 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. Like the above CPU100 %, it is often a life-and-death issue in PHP programs.LoopGdb can be roughly killed after multiple queries.Loop. Ability to solve gdb problemsPHP programmersFew. 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. This typePHP programmersIt is rare. With the gdb tool and familiar with PHP source code, you can view opcode information, execute_data memory,Global variables.

The above introduces the PHP programmer's ability to solve the problem of 8 levels, including the content, hope to be helpful to friends who are interested in PHP tutorials.

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.