In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the tools to make PHP programmers work more efficiently". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what tools to make PHP programmers work more efficiently.
Xdebug
As a developer, the most secure thing to sleep is to know the code you write, both at the functional level and at the performance level. One of the trickier things to do Web PHP development is to debug the code. As a scripting language, running on the remote server, the client side generates all HTML code. It is generally believed that we can not accurately debug the running situation, not to mention single-step debugging, variable monitoring and so on. In fact, there is a misunderstanding that there is a PHP extension Xdebug that allows us to easily debug code running on a remote server.
The method is simple: download the * 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
If you add the corresponding configuration to php.ini, you need to note two points:
1. Xdebug is zend_extension
two。 The default port is 9000, which conflicts with the default port of php-fpm, so 9100 is used 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
So it's installed, it's that simple, and we can start using it. Take ThinkPHP application development as an example. ThinkPHP is a typical single-entry application, and the call level is relatively complex. So it's troublesome to understand the call stack. To get a call stack for a row, you can get it using the debug_backtrace function that comes with PHP, but it doesn't look good, it just returns an array. And Xdebug can make it all visual.
The debugging tool that comes with Xdebug is used with Netbeans. First of all, modify the port of PHP debugging from 9000 to 9100 through the * * item, and don't move the rest. Note that the * line stop is selected, which will stop when the PHP program is debugged, when running to the * line PHP code, and in ThinkPHP, that is, the * line of the entry file index.php.
In this example, the author makes an example of a car rental management system, and the project is called zuches. Deploy the code where http://localhost/zuches can access it, and the index file is index.php.
Since index.php is the entry file, right-click on index.php and select debug.
Then Netbeans automatically opens the following address and enters the debugging state: the location where http://localhost/zuches/index.php?XDEBUG_SESSION_START=netbeans-xdebug is running at the same time indicates that it stops at the * * line of index.php. As follows:
Click continue, and because a breakpoint is added to the index method of IndexController.class.php, the location indication stays at the corresponding breakpoint.
At this point, we can look at the call stack and variables at the time of the interrupt. Through the stack, you can easily locate the positioning classes and corresponding methods.
All kinds of variables, whether local variables and instance properties, whether cookie or submitted data, can be seen in the variable table and can be seen at a glance.
In short, Xdebug allows us to debug every line of code, just like desktop application development, even if we are doing server-side page and API development.
In addition to being used for single-step debugging, Xdebug can also collect the execution logs in the request and record the execution of each function. These logs can be analyzed with tools such as wincachegrind to see the call stack of the function and the time spent. I won't repeat it here, and we don't recommend it very much, because XHProf is much lighter and more powerful in this area, and it doesn't take so much effort to download and analyze logs.
XHProf
As mentioned earlier, for function call stack and performance analysis in PHP, XHProf inherits and carries forward the precedent of Xdebug. XHProf is also an PHP extension, but it is not recommended to download it from http://pecl.php.net/package/xhprof. The version has not been updated for nearly 2 years. * download it from https://github.com/phacility/xhprof. Downloading and compiling the configuration and using it are easy.
You only need to add the following two lines for configuration:
```[xhprof] extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xhprof.so
Then configure the corresponding XHProf code to the page that needs to be monitored, that is, you can get the call report of each function in the execution of the whole page. XHProf provides an example. The configuration runs successfully as follows:
How do you see the effect in the picture above? Put the examples, xhprof_html, and xhprof_lib directories where the browser can access them, such as the home directory of localhost. Modify the change in examples/sample.php to such as localhost/xhprof_html/. That's it.
Then visit http://localhost/examples/sample.php and get the output as follows:
As you can see from examples/sample.php, the monitoring analysis of the page starts with xhprof_enable at the top of the page, while the performance analysis ends with xhprof_disable at the bottom of the page. In this way, each monitoring requires an additional piece of code, so for the sake of specification. The operations related to XHProf are encapsulated. Continue to use the previous example of a ThinkPHP car rental system to see how to integrate XHProf analysis.
First, the operation on XHProf is encapsulated into a class.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.