Once connected to your website, create the following two folders (if they don't exist already):
- \bin
- \bin\xdebug_profiles
Select one of the following two methods:
Method 1: Leave Xdebug Enabled all the Time
Add the following lines to your .user.ini file depending on the version of PHP that your website is using:
a) If using PHP 5.6, 7.0, 7.1 or 7.2 then add the following lines to your .user.ini file:
PHP VERSION |
Lines to copy to .user.ini |
PHP 5.6 |
zend_extension = "D:\devtools\xdebug\2.5.5\php_5.6\php_xdebug-2.5.5-5.6-vc11-nts.dll"
|
PHP 7.0 |
zend_extension = "D:\devtools\xdebug\2.6.0\php_7.0\php_xdebug-2.6.0-7.0-vc14-nts.dll"
xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles"
|
PHP 7.1 |
zend_extension = "D:\devtools\xdebug\2.6.0\php_7.1\php_xdebug-2.6.0-7.1-vc14-nts.dll"
|
PHP 7.2 |
zend_extension = "D:\devtools\xdebug\2.6.0\php_7.2\php_xdebug-2.6.0-7.2-vc15-nts.dll"
|
b) If you have configured your own version of PHP then use the same lines as above just reflecting the right path and DLL name of the XDebug file that you used in the zend_extension property.
Note: Make sure you have enough space in your xdebug.profiler_output_dir as the amount of information generated by the profiler can be enormous for complex scripts. Also note that “site” in the output path should not be replaced with your particular site name.
Method 2: Selectively Enable Xdebug via a Trigger
1. Add the following lines to your .user.ini file depending on the version of PHP that your website is using:
a) If using PHP 5.6, 7.0, 7.1 or 7.2 then add the corresponding lines to your .user.ini file:
PHP VERSION
Lines to copy to .user.ini
PHP 5.6 zend_extension= "D:\devtools\xdebug\2.5.5\php_5.6\php_xdebug-2.5.5-5.6-vc11-nts.dll"
xdebug.profiler_enable=0
xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles"
xdebug.profiler_enable_trigger=1PHP 7.0 zend_extension="D:\devtools\xdebug\2.6.0\php_7.0\php_xdebug-2.6.0-7.0-vc14-nts.dll"
xdebug.profiler_enable=0
xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles"
xdebug.profiler_enable_trigger=1PHP 7.1 zend_extension= "D:\devtools\xdebug\2.6.0\php_7.1\php_xdebug-2.6.0-7.1-vc14-nts.dll"
xdebug.profiler_enable=0
xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles"
xdebug.profiler_enable_trigger=1PHP 7.2 zend_extension= "D:\devtools\xdebug\2.6.0\php_7.2\php_xdebug-2.6.0-7.2-vc15-nts.dll"
xdebug.profiler_enable=0
xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles"
xdebug.profiler_enable_trigger=1
Note: If you use this option then you can leave Xdebug profiling OFF (set to 0) and then it can be triggered with a query string (e.g. http://<yoursite>/<pagename>.php?XDEBUG_PROFILE=1) to profile an individual request instead of profiling your whole site which will affect your website’s performance.
7. Open your website in the Windows Azure Portal, click on the Configure tab, scroll to the App Settings section and add a new key called PHP_ZENDEXTENSIONS with a value pointing to the location of the Xdebug dll:
a) If using PHP 5.4, 5,5, or 5.6 then add the corresponding lines to your Application Settings in the Azure portal:
PHP VERSION | KEY | VALUE |
PHP 5.6 | PHP_ZENDEXTENSIONS | D:\devtools\xdebug\2.5.5\php_5.6\php_xdebug-2.5.5-5.6-vc11-nts.dll |
PHP 7.0 | PHP_ZENDEXTENSIONS | D:\devtools\xdebug\2.6.0\php_7.0\php_xdebug-2.6.0-7.0-vc14-nts.dll |
PHP 7.1 | PHP_ZENDEXTENSIONS | D:\devtools\xdebug\2.6.0\php_7.1\php_xdebug-2.6.0-7.1-vc14-nts.dll |
PHP 7.2 | PHP_ZENDEXTENSIONS | D:\devtools\xdebug\2.6.0\php_7.2\php_xdebug-2.6.0-7.2-vc15-nts.dll |
b) If are using other version of PHP then configure the PHP_ZENDEXTENSIONS to the same value as the zend_extension property that you configured in Step 6.
8. In old portal, click Save at the bottom of the page, in new portal, click Save at the top of the blade:
9. If you are not enabling profiling using a trigger, wait for the problem to happen and then go to Step 10. If you are using a trigger to enable Xdebug profiling, when you notice your application is slow, enable Xdebug profiling by triggering it with a query string in the following form: http://<yoursite>/<pagename>.php?XDEBUG_PROFILE=1
10. All the files will be saved to the /bin/xdebug_profiles folder. The files will start with "cachegrind.out" and end with the PID (process ID) of the PHP-CGI process.
11. Download all the files via FTP using an FTP client like Filezilla . (For more information on accessing your website using FTP, see this blog post .)
12. Once you have collected the Xdebug logs, use WinCacheGrind to read the files and identify slow running methods. You can download WinCacheGrind from http://sourceforge.net/projects/wincachegrind/ .
13. After opening the file, you will see a list of the pages and functions being called and the time spent on each. By drilling down into each parent function/method, you can identify which one(s) are taking the longest time. The screenshot below shows an example. Click the image for a larger image.
14. Once you have identified the function/methods taking the longest time, the application’s developer should take look at the source code and try to understand why is taking that long and how can be improved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.