Backend Development 4 min read

Customizing Xdebug Profiler Output Filename and Analyzing PHP Performance on macOS

This guide explains how to customize Xdebug's profiler output filename using the xdebug.profiler_output_name setting, shows where the generated cachegrind files are stored on macOS, and provides steps to install Graphviz and qcachegrind for performance analysis, plus cleanup commands to remove old profiles.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Customizing Xdebug Profiler Output Filename and Analyzing PHP Performance on macOS

When Xdebug is enabled, the profiler creates output files (typically named cachegrind.out.xxxx ) that can be analyzed with third‑party tools. If you work on multiple projects, having all profiles in a single file becomes inconvenient.

You can customize the output filename by setting the xdebug.profiler_output_name directive in php.ini . The directive supports several placeholders:

Symbol

Meaning

Example Pattern

Resulting Filename

%c

CRC32 of the current working directory

cachegrind.out.%c

cachegrind.out.1258863198

%p

Current process ID

cachegrind.out.%p

cachegrind.out.9685

%r

Random number

cachegrind.out.%r

cachegrind.out.072db0

%s

Script filename

cachegrind.out.%s

cachegrind.out._home_httpd_html_test_xdebug_test_php

%t

Unix timestamp (seconds)

cachegrind.out.%t

cachegrind.out.1179434742

%u

Unix timestamp (microseconds)

cachegrind.out.%u

cachegrind.out.1179434749_642382

%H

$_SERVER["HTTP_HOST"]

cachegrind.out.%H

cachegrind.out.localhost

%R

$_SERVER["REQUEST_URI"]

cachegrind.out.%R

cachegrind.out._test_xdebug_test_php_var=1_var2

%S

Session ID (from $_COOKIE if set)

cachegrind.out.%S

cachegrind.out.c70c1ec2375af58f74b390bbdd2a679d

%%

Literal % character

cachegrind.out.%%

cachegrind.out.%%

Edit php.ini and add a line such as:

<code>xdebug.profiler_output_name = cachegrind.out.%H</code>

After saving the file, restart your PHP server.

On macOS, the profile files are stored in the /var/tmp/ directory.

For performance analysis, you can use MacCallGrind (paid) or the free qcachegrind . Both require Graphviz for call‑graph visualization.

Install the required tools with Homebrew:

<code>$ brew install graphviz</code>
<code>$ brew install qcachegrind</code>

Once installed, launch qcachegrind and open a cachegrind.out.* file to view the graphical analysis.

Be aware that enabling profiling can quickly fill disk space if many projects generate files. You can clean up old profiles with:

<code>$ sudo rm -fr /private/var/tmp/cachegrind.out.*</code>

Regular cleanup helps prevent excessive disk usage.

backendPerformancePHPmacOSprofilingxdebugqcachegrind
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.