LinuxCommandLibrary

blackfire

Profile PHP applications performance

TLDR

Initialize and configure the Blackfire client

$ blackfire config
copy

Launch the Blackfire agent
$ blackfire agent
copy

Launch the Blackfire agent on a specific socket
$ blackfire agent --socket="[tcp://127.0.0.1:8307]"
copy

Run the profiler on a specific program
$ blackfire run [php path/to/file.php]
copy

Run the profiler and collect 10 samples
$ blackfire --samples 10 run [php path/to/file.php]
copy

Run the profiler and output results as JSON
$ blackfire --json run [php path/to/file.php]
copy

Upload a profiler file to the Blackfire web service
$ blackfire upload [path/to/file]
copy

View the status of profiles on the Blackfire web service
$ blackfire status
copy

SYNOPSIS

blackfire [options] <command> [<args>]

PARAMETERS

-q, --quiet
    Do not output any message

-V, --version
    Display application version

--ansi
    Force ANSI output

--no-ansi
    Disable ANSI output

-n, --no-interaction
    Do not ask interactive questions

-v|-vv|-vvv, --verbose
    Increase verbosity (1=normal, 2=verbose, 3=debug)

--config FILE
    Path to configuration file

--socket SOCKET
    Path to agent socket

DESCRIPTION

Blackfire is a powerful performance analysis tool for PHP applications, enabling developers to profile code in development, staging, and production environments with negligible overhead. The blackfire command-line interface serves as the primary entry point for managing the Blackfire agent, executing profiles, configuring settings, and generating reports.

It excels at identifying bottlenecks in CPU usage, memory allocation, I/O operations, database queries, and external calls. Using a patented probing technology, it instruments PHP code dynamically without requiring code changes. Key features include wall-time profiling, call graphs, flame graphs, and recommendations for optimizations.

The CLI supports subcommands like agent for starting the server-side agent, curl for profiling HTTP requests, php and exec for scripting, and status for diagnostics. It integrates seamlessly with Blackfire.io for online dashboards, alerts, and continuous monitoring. Requires a free Blackfire account for full features, with client/server IDs for authentication.

Ideal for Symfony, Laravel, and custom PHP apps, it provides actionable insights beyond traditional tools like Xdebug.

CAVEATS

Requires Blackfire account credentials; PHP extension or agent must be installed separately. Minimal overhead but not zero; production use needs caution. Linux/macOS/Windows supported, but agent socket paths vary.

COMMON SUBCOMMANDS

agent: Manage profiling agent.
curl URL: Profile HTTP requests.
php script.php: Profile PHP scripts.
status: Check components.

INSTALLATION

curl -s https://packagecloud.io/install/repositories/blackfireio/blackfire/script.deb.sh | sudo bash
sudo apt-get install blackfire/blackfire-agent blackfire

HISTORY

Developed by SensioLabs (creators of Symfony) around 2013; acquired by Blackfire.io. CLI evolved with Symfony Console framework. Major versions align with PHP 5.3+ support, now PHP 8.x compatible.

SEE ALSO

php(1), curl(1), strace(1), perf(1)

Copied to clipboard