PHP programmer Eight levels of problem solving skills _php Tutorial

Source: Internet
Author: User
Tags php error php source code

PHP programmer Eight levels of problem-solving capabilities


The topic of old growth talk, in the interview of the ability of the inevitable assessment, I personally think the problem-solving ability is ranked first, higher than the ability to learn the 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. If the problem solving ability is not able to pass the interview.

For example, if I execute a PHP script, such as PHP test.php, it is expected to return a string. But there is no information output after execution, and by what means can we know where the program is wrong? The ability to solve problems can be divided into 8 levels, the more to the back of the more powerful representation.

Lv0 Viewing PHP error messages

The program did not achieve the desired results, proving that the code is wrong, see PHP error message is the first step. If you ignore the error message directly, it indicates that this person is not suitable for a professional programmer post. In some cases, the error display is turned off in the php.ini configuration, the php.ini open error message needs to be modified, or the error message is exported to the log file, which can be directly TAILF php_error.log the error message.

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

Note: The way to open the error display is

    • PHP.ini in Display_errors/display_startup_errors set to ON

    • PHP.ini in error_reporting set to E_all

    • Set error_reporting (e_all) in PHP code

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 at by which PHP, or add an absolute path to the PHP version. Indicates that this phper passed the 50% test at this level.

Another situation is that php-cli and PHP-FPM get a different implementation, such as executing in a Web browser is correct, the CLI execution is wrong. This can be caused by the php.ini of 2 environments loading. Which php.ini is loaded under the CLI through the Php-i |grep php.ini. The absolute path of php.ini can be obtained by using the Phpinfo () function under FPM.

LV2 Var_dump/die Print Variable value information Single step debugging

This is the usual program debugging means, but also the simplest and most effective method of solving problems. The high-level approach is to use the PHP Trace class/Log class, a bit more fancy can be phpstorm+xdebug in the IDE tool Debug.

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

These 3 tests all passed, indicating that the programmer has the ability to solve problems that a professional PHP programmer should have. As long as the PHP programmer over this level, it should be more than the majority of cases, in small and medium-sized sites without pressure.

Lv3 using 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 and grasp the process of program execution. This method is most commonly used in large-scale websites and large companies. If not master Strace, here can only say sorry, we do not accept not strace phper.

Strace is actually the test of the programmer Foundation, if do not understand operation operating system, completely do not understand the bottom, certainly also can not reach to use Strace degree. Of course, Strace is not a solution to the dead loop in PHP code. For example, you find a php-fpm process cpu100%, strace I am afraid can not solve. Since Strace is looking at system calls, which are generally IO class operations, since it is IO intensive, that CPU must not be 100%.

LV4 analyzing the network communication process using the Tcpdump tool

Tcpdump can catch the data communication process of the network card, even the content can be captured. Using Tcpdump, you can see what the network communication process is, how to initiate a TCP SYN3 handshake, when to send the FIN packet, and when to send the RST package. This is a basic skill, if does not understand tcpdump, proves that does not have the network problem solves the ability.

LV5 time and success of statistical function calls

Use Xhporf/xdebug to export the call procedure for PHP requests, and then analyze the process and time-consuming of each function call. Ability to analyze performance bottlenecks in PHP programs to identify points that can be optimized.

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

LV6 GDB uses

GDB is a powerful tool for the C/s + + Debug program, which requires a programmer with a certain C + + knowledge to use gdb skillfully. Above said Strace cannot track PHP program cpu100%, and GDB can be traced. In addition, GDB can also solve the PHP program core dump problem.

You can easily track the execution of your PHP program by gdb-p the process ID and PHP-SRC with tools such as the. Gdbinit zbacktrace. Like the above cpu100% is often the PHP program in a dead loop, gdb to do multiple viewing, you can roughly get the location of the dead loop. There are few PHP programmers with GDB problem-solving skills. If you can use GDB to solve PHP problems, this phper can pass the interview, and can get a high technical rating.

LV7 View PHP kernel and extended source code

If you can be familiar with the PHP kernel and the extension of the source code, the PHP program encountered the most complex memory errors, can also have the ability to solve. This type of PHP programmer is a rarity. With GDB tools and familiarity with 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

http://www.bkjia.com/PHPjc/1051850.html www.bkjia.com true http://www.bkjia.com/PHPjc/1051850.html techarticle PHP Programmer problem-solving ability of the eight levels of the topic of the old growth talk, in the interview of the ability to assess the inevitable, I personally think the problem-solving ability is ranked first, than learning can ...

  • 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.