Four wonders to make PHP programmers work more efficiently (1)

Source: Internet
Author: User
Tags config end execution variables php and php code variable netbeans





Do the program ape "Yuan" is a bitter forced to live, Saturday early in the technical group to greet, see no one response, said a, "not expected to wake up", and then a friend thrown over, "in overtime"!



Do WEB development is a bitter force of life, not like to do IOS, to fix the client, basically everything is all right. Do WEB development is not only to do the backend, front-end also need to understand and familiar!



Do before and after the end of all DevOps the entire stack of engineers is absolutely the most difficult to live, not only need to do development, but also to understand the operation of the dimension, optimization, not operational dimension of the engineer is definitely not a good architect!



Fortunately, though, a good engineer, despite being busy, is familiar with front and rear, system, operation, and optimization, but in his toolbox, there are a lot of tools to make this life less bitter.



Here are four artifacts that let us DevOps our lives to become better. respectively, Xdebug, Xhprof, ONEAPM and Socketlog.



Xdebug



As a developer, the most practical thing to sleep is to know the code that you write, whether it's from the functional level or the performance level. And do Web PHP development, the more difficult thing is the debugging of the code. As a scripting language, run on the remote server, the client generated is all HTML code, generally think we can not accurately debug the operation of the situation, not to mention the single step debugging, variable monitoring and other things. In fact, there is a misunderstanding that there is a PHP extension Xdebug that allows us to easily debug the code running on the remote server.



The method is simple, download the latest version of the source code from Xdebug. Wget Decompression:



tar –zxvf xdebug-2.3.3.tgz
cd xdebug-2.3.3 phpize
./configure –with-php-config=/usr/bin/php-config
make
make install



Add the corresponding configuration tophp.ini, you need to note that there are two points:



1. Xdebug is Zend_extension



2. The port defaults to 9000, and the default port for PHP-FPM conflicts, so swap 9100 here



[xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9100



That's it, it's just so simple, we can start using it now. Take thinkphp application development as an example. thinkphp Typical single entry application, the call level is relatively complex. So trying to understand the call stack is tricky. To get a call stack for a row, you can use PHP's owndebug_backtracefunction to obtain it, but it's not a very image, but it returns an array. And Xdebug can make all of this visible.



The Xdebug uses the debugging tools from Netbeans. First through the preferences to modify the PHP debugging port, from 9000 to 9100, the others do not move. Note that the first line stop is optional, which will stop when the PHP program is debugged, when it runs to the first line of PHP code, in thinkphp, the first line of the entry file index.php.






In this case, the author made a car rental management System example, the project name is zuches . Deploy your code where youhttp://localhost/zuchescan access it, and the index file is index.php.






Since index.php is the entry file, right-click on the index.php and select Debug.






Then Netbeans automatically opens the following address and goes to the debug state: Thehttp://localhost/zuches/index.php?XDEBUG_SESSION_START=netbeans-xdebugrunning position indicates the first line of the index.php. As follows:






Click Continue to run, because inIndexController.class.phpthe method of adding a breakpointindex, so the position indicator is stuck in the corresponding breakpoint.






At this point, we can look at the call stack and variables at the time of interruption. The stack makes it easy to navigate to the various positioning classes and corresponding methods.






variables, whether local variables and instance properties, whether cookies, or submit data, can be seen in the variable table, at a glance.






In short, Xdebug lets us even do the server-side page and API development, as well as desktop application development, can debug every line of code.



In addition to being used for Single-step debugging, Xdebug can collect execution logs from requests and record the execution of each function. These logs can bewincachegrindanalyzed using tools such as the call stack of functions and the time spent. Here no longer to repeat, we are not very recommended, becauseXHProfin this piece to lightweight and more powerful, do not have so much trouble underground download log, analysis log.





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.