Eight levels of problem-solving skills for PHP programmers

Source: Internet
Author: User
Tags execution fpm mysql query php code php error php script variable versions

The topic of old growth talk, in the interview will be the ability to assess, I personally think that the problem-solving ability is ranked first, higher than the learning ability priority. The ability to solve problems can not only see the programmer's thinking ability, adaptability, exploration ability and so on, but also can see his experience. It is impossible to pass the interview if the problem solving ability is poor.

For example, if I execute a PHP script, such as PHP test.php, it is expected to be able to return a string. But without any information output after execution, what is the way to know where the program is wrong? Here you can divide the problem-solving capability into 8 levels, with the ability to represent the latter more strongly.

Lv0 View PHP error messages

The program did not achieve the expected effect, proof code error, see PHP error message is the first step. If you ignore the error message directly, 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, which can be directly TAILF Php_error.log to see the error message.

Get the error message directly to the program code problem, or to google/Baidu search, you can solve the problem.

Note: The way to turn on the error display is

    • Display_errors/display_startup_errors set to ON in php.ini

    • Error_reporting set to E_all in php.ini

    • Set error_reporting in PHP code (e_all)

LV1 There are multiple versions of PHP or PHP-CLI with php-fpm loading different configurations

There are multiple versions of PHP, know which PHP to look through which PHP, or add absolute path to develop PHP version. That Phper passed the 50% test at this level.

Another situation is that PHP-CLI is not performing the same way as php-fpm, as execution is correct in a Web browser, and execution under the CLI is wrong. This may be the result of a different php.ini load of 2 environments. Which php.ini are loaded under the CLI via php-i grep php.ini. The absolute path of php.ini can be obtained by the phpinfo () function under FPM.

LV2 Var_dump/die Printing Variable value information Single step debugging

This is the usual program debugging methods, but also the simplest and most effective solution to the problem. A more advanced approach is to use the Trace class/log class in PHP, which is a little bit more flashy and can be debug in the IDE's tools with the help of Phpstorm+xdebug.

The trace tool can also analyze the time-consuming script and optimize the performance of the PHP program.

These 3 tests all pass, indicating that this programmer already has the professional PHP programmer should have the problem solving ability. As long as the PHP programmer passed this level, it should be enough for most of the situation, no pressure on the small and medium Web sites.

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 IDs. Strace can help you to understand the nature of the phenomenon, master the process of program execution. This means the most commonly used in large websites, large companies. If not master Strace, here can only say sorry, we do not accept not strace phper.

Strace is also the test of the basic programmer, if you do not know how to operate the operating system, completely do not understand the bottom, certainly not to use Strace degree. Of course strace can not solve the dead loop in the PHP code. For example, you find a php-fpm process cpu100%, strace I am afraid can not solve. Because Strace is to see system call, is generally IO class operation, since is IO intensive, that CPU must not be 100%.

Lv4 using the Tcpdump tool to analyze the network communication process

Tcpdump can catch the network card data communication process, and even the content can be caught. Using Tcpdump, you can see what the network communication process is like, how to initiate a TCP SYN3 handshake, when to send a FIN packet, and when to send the RST packet. This is a basic skill, if do not understand tcpdump, prove not to have network problem solving ability.

The time consuming and success rate of LV5 statistical function call

Use Xhporf/xdebug to export the call procedure for the PHP request, and then analyze the process and time consuming of each function call. Can analyze the performance bottleneck of PHP program, find out the point that can optimize.

Another call to network services, such as MySQL query, curl, other API calls, by recording the start and end of the Microtime, return is not false, you can get the success of the call, how much time. If you can summarize the data, sorting out the success rate of calls, failure rates, average latency, proving that the programmer is sensitive to interface quality, has a large web site project experience.

LV6 GDB uses

GDB is a good tool for C/s + + debugger, and it requires a programmer with a certain C + + skills to be proficient with GDB. The strace can't track the PHP program cpu100%, and GDB can track it. In addition GDB can also solve the PHP program core dump problem.

The execution of PHP programs can be easily tracked by gdb-p process IDs, and then with tools such as PHP-SRC. Gdbinit Zbacktrace. Like the above cpu100% is often a dead loop in the PHP program, GDB for many times to see, can be roughly the location of the dead loop. There are few PHP programmers with GDB problem-solving capabilities. If you can use GDB to solve PHP problems, this phper can be fully interviewed and can get a higher technical rating.

LV7 View PHP kernel and extended source

If you can familiarize yourself with the PHP kernel and the extended source code, you will have the ability to solve the most complex memory errors in your PHP program. This kind of PHP programmer is very rare. With the GDB tool and familiar with the PHP source code, you can view opcode information, execute_data memory, global variable status, and so on.

What level are you?

Original: http://rango.swoole.com/archives/340 Author: @ Hantian-rango

Related Article

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.