# Xdebug profiling doesn't work

**URL:** <https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909>\
**Category:** Support\
**Tags:** xdebug\
**Created:** [June 11, 2021, 7:00am UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909 "2021-06-11T07:00:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProxxiM](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/proxxim/32/5784_2.png) [@ProxxiM](https://community.localwp.com/u/ProxxiM)\
**Post date:** [June 11, 2021, 7:00am UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/1 "2021-06-11T07:00:33Z")

</div>

For a client I need to investigate what functions/code slows down their platform the most. The best thing I could have is an overview of how long every PHP function takes to execute. I can’t find any good solutions for this, apart from Xdebug profiling.

At the moment Local has Xdebug v2.9 built-in, but I can’t figure out how to start profiling. I added the code below in the PHP configuration, but it doesn’t seem to do anything when I restart the server. I can see the settings have been applied when I look into phpinfo(), but there are no logging/profiling files appearing in the directory.

```
xdebug.remote_autostart=1
xdebug.profiler_append=1
xdebug.remote_connect_back=On
xdebug.profiler_enable=1
xdebug.profiler_output_dir=""
xdebug.profiler_enable_trigger=1

```

I checked out various support topics and blogs, but didn’t find a solution yet. Who can help me out with this?

---

<div class="post-metadata">

**Author:** ![ben.turner](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/ben.turner/32/5366_2.png) [@ben.turner](https://community.localwp.com/u/ben.turner)\
**Post date:** [June 11, 2021, 9:31pm UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/2 "2021-06-11T21:31:01Z")

</div>

I haven’t ever tried getting this to work, so I’d be curious to know what you find out.

In general, when I’m investigating performance issues with WordPress sites, it’s more likely an issue with the DB and any complex queries that are being run. As an initial look at things, have to installed and enabled Query Monitor and viewed what kinds of queries are being run to generate the page you are wanting to optimize?

> **[Query Monitor](https://wordpress.org/plugins/query-monitor/)**
>
> Query Monitor is the developer tools panel for WordPress.

To your specific question of Xdebug, I took a look at the [Starting the profiler](https://xdebug.org/docs/profiler#starting) doc – it mentions that you might need to add this to the `php.ini.hbs` config file and restart the Local site:

```auto
xdebug.mode=profile

```

---

<div class="post-metadata">

**Author:** ![ProxxiM](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/proxxim/32/5784_2.png) [@ProxxiM](https://community.localwp.com/u/ProxxiM)\
**Post date:** [June 14, 2021, 7:47am UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/3 "2021-06-14T07:47:09Z")

</div>

Well the thing with Query Monitor is that it mainly gives insight in SQL-queries but not so much in what PHP-functions are actually running and/or how long they take or how many times they are being started.

I feel like we did as much as we can optimising the SQL-part of our platform, but maybe there’s PHP-functions could be optimised more.

---

<div class="post-metadata">

**Author:** ![ben.turner](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/ben.turner/32/5366_2.png) [@ben.turner](https://community.localwp.com/u/ben.turner)\
**Post date:** [June 14, 2021, 4:05pm UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/4 "2021-06-14T16:05:05Z")

</div>

Nice! PHP performance in WordPress is something that I’d love to have more experience with, so as you work through this, I’d love to review your findings.

Maybe you’ve seen this already, but for a while there this tool was something I turned to for quickly zeroing in on different problem functions:

> **[wp-cli/profile-command](https://github.com/wp-cli/profile-command)**
>
> Quickly identify what's slow with WordPress. Contribute to wp-cli/profile-command development by creating an account on GitHub.

```auto
wp package install wp-cli/profile-command:@stable

```

As of newer versions of PHP, this tool isn’t as precise because a number of the functions that are added to hooks aren’t recorded.

---

<div class="post-metadata">

**Author:** ![ProxxiM](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/proxxim/32/5784_2.png) [@ProxxiM](https://community.localwp.com/u/ProxxiM)\
**Post date:** [June 15, 2021, 2:15pm UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/5 "2021-06-15T14:15:17Z")

</div>

Hi Ben,

When I try to install the package in the Site Shell I am receiving the following error:  
`Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 2267527 bytes) in phar:///Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/composer/composer/src/Composer/Util/RemoteFilesystem.php on line 461`

---

<div class="post-metadata">

**Author:** ![ben.turner](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/ben.turner/32/5366_2.png) [@ben.turner](https://community.localwp.com/u/ben.turner)\
**Post date:** [June 16, 2021, 3:34pm UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/6 "2021-06-16T15:34:44Z")

</div>

Ooof. I always forget that Composer (what wpcli uses to install packages) is such a memory hog.

See this WP make post for the background info: [Common Issues – WP-CLI – WordPress.org](https://make.wordpress.org/cli/handbook/guides/common-issues/#php-fatal-error-allowed-memory-size-of-999999-bytes-exhausted-tried-to-allocate-99-bytes)

In the context of a Local site, you basically need to increase the memory limit for the PHP process. To do that:

1. Open the `php.ini.hbs` file for the site and increase the memory limit.
2. Save the file and restart the Local site to re-compile that configuration

When I did it, I had to go all the way to 1Gb to get that package to install:

 ![Image 2021-06-16 at 8.27.43 AM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/7/786877c279fd70b16cd135495340f37bf4e7f606.jpeg)

After that, check out the docs for more usage info, but for example, on a plain wp site, I can profile the `/sample-page/` and in particular the `init` hook for that page:

```auto
★ app/public % wp profile stage --all --url='http://profiling-php.local/sample-page/'
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| hook | callback_count | time | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| muplugins_loaded:before | 0 | 0.148s | 0.0005s | 1 | 25% | 1 | 3 | 0s | 0 |
| muplugins_loaded | 2 | 0.0001s | 0s | 0 | | 0 | 0 | 0s | 0 |
| plugins_loaded:before | 0 | 0.0675s | 0s | 0 | 47.06% | 8 | 9 | 0s | 0 |
| plugins_loaded | 4 | 0.0079s | 0s | 0 | | 0 | 0 | 0s | 0 |
| setup_theme:before | 0 | 0.0006s | 0s | 0 | 50% | 2 | 2 | 0s | 0 |
| setup_theme | 2 | 0.0024s | 0s | 0 | | 0 | 0 | 0s | 0 |
| after_setup_theme:before | 0 | 0.0308s | 0.0002s | 1 | 95.65% | 88 | 4 | 0s | 0 |
| after_setup_theme | 2 | 0.0052s | 0s | 0 | 100% | 6 | 0 | 0s | 0 |
| init:before | 0 | 0.0033s | 0s | 0 | 100% | 2 | 0 | 0s | 0 |
| init | 32 | 0.1175s | 0.0007s | 2 | 98.95% | 188 | 2 | 0s | 0 |
| wp_loaded:before | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_loaded | 2 | 0.0003s | 0s | 0 | 100% | 2 | 0 | 0s | 0 |
| parse_request:before | 0 | 0.0316s | 0.0016s | 2 | 57.14% | 4 | 3 | 0s | 0 |
| parse_request | 1 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| send_headers:before | 0 | 0.0004s | 0s | 0 | 100% | 4 | 0 | 0s | 0 |
| send_headers | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| pre_get_posts:before | 0 | 0.0004s | 0s | 0 | 100% | 7 | 0 | 0s | 0 |
| pre_get_posts | 1 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| the_posts:before | 0 | 0.0049s | 0.001s | 4 | 41.67% | 5 | 7 | 0s | 0 |
| the_posts | 2 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp:before | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| template_redirect:before | 0 | 0.0005s | 0s | 0 | | 0 | 0 | 0s | 0 |
| template_redirect | 7 | 0.0025s | 0s | 0 | 100% | 21 | 0 | 0s | 0 |
| template_include:before | 0 | 0.0008s | 0s | 0 | 100% | 9 | 0 | 0s | 0 |
| template_include | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_head:before | 0 | 0.0032s | 0s | 0 | 100% | 10 | 0 | 0s | 0 |
| wp_head | 25 | 0.0221s | 0s | 0 | 96.39% | 160 | 6 | 0s | 0 |
| loop_start:before | 0 | 0.01s | 0.0011s | 1 | 98.73% | 78 | 1 | 0s | 0 |
| loop_start | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| loop_end:before | 0 | 0.0091s | 0.0006s | 2 | 90.63% | 29 | 3 | 0s | 0 |
| loop_end | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_footer:before | 0 | 0.0179s | 0.0017s | 7 | 86.59% | 71 | 11 | 0s | 0 |
| wp_footer | 5 | 0.0015s | 0s | 0 | 100% | 4 | 0 | 0s | 0 |
| wp_footer:after | 0 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (35) | 85 | 0.4888s | 0.0074s | 20 | 84.39% | 699 | 51 | 0s | 0 |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
★ app/public % wp profile hook init --url='http://profiling-php.local/sample-page/'
+--------------------------------------------+-------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| callback | location | time | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+--------------------------------------------+-------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| function(){} | phar:///Applications/Local.app/Contents/Resourc | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| | es/extraResources/bin/wp-cli/wp-cli.phar/vendor | | | | | | | | |
| | /wp-cli/wp-cli/php/WP_CLI/Runner.php:1514 | | | | | | | | |
| create_initial_post_types() | wp-includes/post.php:20 | 0.0447s | 0s | 0 | | 0 | 0 | 0s | 0 |
| create_initial_taxonomies() | wp-includes/taxonomy.php:24 | 0.0148s | 0s | 0 | 100% | 20 | 0 | 0s | 0 |
| wp_widgets_init() | wp-includes/widgets.php:1751 | 0.038s | 0.0002s | 1 | 99.33% | 148 | 1 | 0s | 0 |
| smilies_init() | wp-includes/functions.php:4328 | 0.0004s | 0s | 0 | 100% | 2 | 0 | 0s | 0 |
| localwp_auto_login() | /Applications/Local.app/Contents/Resources/extr | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| | aResources/local-bootstrap.php:10 | | | | | | | | |
| function(){} | phar:///Applications/Local.app/Contents/Resourc | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| | es/extraResources/bin/wp-cli/wp-cli.phar/vendor | | | | | | | | |
| | /wp-cli/wp-cli/php/WP_CLI/Runner.php:1565 | | | | | | | | |
| wp_init_targeted_link_rel_filters() | wp-includes/formatting.php:3253 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| _register_core_block_patterns_and_categori | wp-includes/block-patterns.php:17 | 0.006s | 0s | 0 | | 0 | 0 | 0s | 0 |
| es() | | | | | | | | | |
| wp_cron() | wp-includes/cron.php:947 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_schedule_https_detection() | wp-includes/https-detection.php:163 | 0.0002s | 0s | 0 | 100% | 2 | 0 | 0s | 0 |
| wp_schedule_delete_old_privacy_export_file | wp-includes/functions.php:7373 | 0.0002s | 0s | 0 | 100% | 2 | 0 | 0s | 0 |
| s() | | | | | | | | | |
| _show_post_preview() | wp-includes/revision.php:607 | 0s | 0s | 0 | | 0 | 0 | 0s | 0 |
| rest_api_init() | wp-includes/rest-api.php:163 | 0.0002s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_sitemaps_get_server() | wp-includes/sitemaps.php:22 | 0.0014s | 0s | 0 | 100% | 6 | 0 | 0s | 0 |
| kses_init() | wp-includes/kses.php:2133 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| wp_schedule_update_checks() | wp-includes/update.php:849 | 0.0005s | 0s | 0 | 100% | 6 | 0 | 0s | 0 |
| register_block_core_archives() | wp-includes/blocks/archives.php:111 | 0.0004s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_block() | wp-includes/blocks/block.php:64 | 0.0005s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_calendar() | wp-includes/blocks/calendar.php:52 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_categories() | wp-includes/blocks/categories.php:89 | 0.0004s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_latest_comments() | wp-includes/blocks/latest-comments.php:148 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_latest_posts() | wp-includes/blocks/latest-posts.php:197 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_rss() | wp-includes/blocks/rss.php:98 | 0.0004s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_search() | wp-includes/blocks/search.php:112 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_shortcode() | wp-includes/blocks/shortcode.php:23 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_social_link() | wp-includes/blocks/social-link.php:49 | 0.0003s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_block_core_tag_cloud() | wp-includes/blocks/tag-cloud.php:46 | 0.0002s | 0s | 0 | | 0 | 0 | 0s | 0 |
| register_core_block_types_from_metadata() | wp-includes/blocks/index.php:27 | 0.0067s | 0s | 0 | | 0 | 0 | 0s | 0 |
| twenty_twenty_one_register_block_styles() | twentytwentyone/inc/block-styles.php:20 | 0.0011s | 0s | 0 | | 0 | 0 | 0s | 0 |
| WP_Block_Supports::init() | wp-includes/class-wp-block-supports.php:65 | 0.001s | 0s | 0 | | 0 | 0 | 0s | 0 |
| check_theme_switched() | wp-includes/theme.php:3276 | 0.0007s | 0.0003s | 1 | 66.67% | 2 | 1 | 0s | 0 |
+--------------------------------------------+-------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (32) | | 0.1199s | 0.0005s | 2 | 95.75% | 188 | 2 | 0s | 0 |
+--------------------------------------------+-------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+

```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/system/32/1_2.png) [@system](https://community.localwp.com/u/system)\
**Post date:** [September 14, 2021, 3:34pm UTC](https://community.localwp.com/t/xdebug-profiling-doesnt-work/25909/7 "2021-09-14T15:34:44Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
