Configure X-Debug to identify Performance Issues in Site

I have installed x-debug on local, got the vs-code extension however, I am now trying to enabling profiling as I have a performance issue on my WordPress site and want to identify what it is exactly.

I have been trying to modify the php.ini.hbs file in order to get the logs appearing in the /logs directory under a file name such as cachegrind.out.* however this is not working.

This is what I have added to the php.ini.hbs file
[xdebug]

{{#if os.windows}}

zend_extension = php_xdebug.dll

{{else}}

zend_extension = {{extensionsDir}}/xdebug.so

{{/if}}

{{#if xdebugEnabled}}

xdebug.mode=debug,develop,profile

{{else}}

xdebug.mode=off

{{/if}}

xdebug.client_port=9003

xdebug.start_with_request=yes

xdebug.discover_client_host=yes

xdebug.output_dir=“{{appRoot}}/logs”

I created my own php.ini file and added:

[xdebug]

xdebug.mode=debug,develop,profile
xdebug.profiler_enable=1
xdebug.profiler_output_dir=“/Users/MyName/Local Sites/myWebsite/logs/”
xdebug.profiler_output_name=“cachegrind.out.%p”

Does not work, cannot see the logs coming through. I don’t think it is ready the php.ini file as it is reading the php.ini.hb file instead…

Surely there is a document somewhere on how to setup xdebug with the profiler in order to identify performance issues ?

Hi @sigurdwattdev! When you’re making changes to php.ini.hbs you have to save them and then Stop and Restart your site so that Local can recompile any changes. Have you tried that?

We also have a guide that goes over some performance troubleshooting here:

Additionally, there are some plugins mentioned in this article as well that can be useful for investigating resource hogs for example if you have a memory leak:

Yes I restarted it multiple times. Can you check the config which i have in that file to ensure that it is fine ? And if you have a config that you know works would be great to see that.

Also I assume it is ignoring the php.ini file ?

Thanks for your reply!

Can you share your OS / OS version @sigurdwattdev?

Also are you on the latest Local release?

Yes I am on the latest version of Local.

Darwin Sigurds-MacBook-Pro-2.local 23.6.0 Darwin Kernel Version 23.6.0: Fri Nov 15 15:13:28 PST 2024; root:xnu-10063.141.1.702.7~1/RELEASE_X86_64 x86_64

Here’s a php.ini.hbs config that works for me to generate profiler output, @sigurdwattdev.

Just as you suspected, it’s important to only edit the php.ini.hbs file. The php.ini itself gets regenerated on site start based on the contents of the .hbs version, so any edits you make directly to php.ini are overwritten.

[xdebug]

{{#if os.windows}}
zend_extension = php_xdebug.dll
{{else}}
zend_extension = {{extensionsDir}}/xdebug.so
{{/if}}

{{#if xdebugEnabled}}
xdebug.mode=debug,develop,profile
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.discover_client_host=yes
xdebug.log_level=0
xdebug.start_with_request=yes
xdebug.output_dir="/Users/[username]/Local Sites/[local-site-name]/logs"
{{else}}
xdebug.mode=off
{{/if}}

When I restart my site and visit it in the browser, I see cachegrind output in the logs folder.

> ls /Users/[username]/Local\ Sites/[local-site-name]/logs
cachegrind.out.50297.gz cachegrind.out.50307.gz cachegrind.out.50318.gz php
cachegrind.out.50299.gz cachegrind.out.50308.gz cachegrind.out.50319.gz
cachegrind.out.50300.gz cachegrind.out.50315.gz cachegrind.out.50328.gz
cachegrind.out.50301.gz cachegrind.out.50316.gz nginx

I tested this with PHP 8.2.23 and nginx under macOS.

1 Like