Skip to content

Profiling PHP in production with Blackfire and Tideways

Compare Blackfire and Tideways for continuous PHP profiling in production, covering agent architecture, overhead, sampling modes, and integration with CI and alerting.

Development profiling tools — Xdebug with XDEBUG_TRIGGER, custom timing wrappers, memory_get_peak_usage() sprinkled in middleware — stop scaling when the problem only manifests under production load patterns, after specific data has accumulated in caches, or on code paths that require authenticated sessions. Blackfire and Tideways are the two PHP-specific production profilers worth knowing in depth. This article covers their architectural differences, the overhead trade-offs, and how to instrument a production FPM host with each.

How to verify

# check if blackfire probe is installed
php -m | grep blackfire
php -i | grep 'blackfire.server_id'

# check if tideways extension is installed
php -m | grep tideways
php -i | grep tideways.api_key

# verify the agent (daemon) is running
systemctl status blackfire-agent
systemctl status tideways-daemon

# test a trace from the command line
blackfire curl https://app.example.com/api/endpoint
tideways trace php artisan queue:work --once

Neither profiler requires application code changes for basic instrumentation — they inject at the extension layer. You do not need require 'vendor/blackfire.php' for standard HTTP profiling.

What’s happening

Blackfire uses an on-demand model. The Blackfire probe (PHP extension) is dormant — zero overhead — until it receives a profiling request, identified by a signed header added by the Blackfire CLI, browser extension, or SDK. When triggered, the probe collects a full call graph with wall time, CPU time, memory allocations, and I/O per function call. The call graph is sent to the Blackfire agent (local daemon), then uploaded to Blackfire’s SaaS for storage and visualization. Overhead during an active profile is significant (roughly 20–30% additional CPU), but because it is request-scoped and triggered explicitly, it does not affect other concurrent requests.

Tideways uses a continuous sampling model. The extension runs in every request and collects a sampled call stack at a configurable rate (default: 25 samples/second per worker). This low-overhead continuous collection (typically under 2% CPU overhead) feeds a local daemon that aggregates traces and ships them to Tideways’ SaaS or a self-hosted instance. Because every request contributes samples, Tideways naturally captures problems that only appear under specific load patterns, time-of-day traffic shapes, or particular data states — problems that on-demand profilers miss because you cannot predict when to trigger them.

The architectural difference maps to two distinct use cases:

  • Blackfire: debugging a known performance issue, profiling specific routes, CI regression testing via the Blackfire API, measuring the exact impact of an optimization.
  • Tideways: observing aggregate performance of the entire application over time, finding which routes are slow in production, correlating performance regressions with deploys, on-call triage.

Both support PHP 8.x. Both have agent-side SDKs for custom spans.

The procedure

Installing Blackfire on Ubuntu 22.04 / PHP 8.3 FPM

  1. Add the Blackfire repository and install:

    curl -sSL https://packages.blackfire.io/gpg.key | sudo gpg --dearmor \
      -o /usr/share/keyrings/blackfire.gpg
    echo "deb [signed-by=/usr/share/keyrings/blackfire.gpg] \
      http://packages.blackfire.io/debian any main" \
      | sudo tee /etc/apt/sources.list.d/blackfire.list
    sudo apt update && sudo apt install -y blackfire blackfire-php
  2. Configure the server credentials (from your Blackfire account):

    sudo blackfire agent:config --server-id=YOUR_ID --server-token=YOUR_TOKEN
    sudo systemctl enable --now blackfire-agent
  3. Verify the probe loaded:

    php -m | grep blackfire
    # should show: blackfire
    sudo systemctl reload php8.3-fpm
  4. Profile a request:

    blackfire curl https://app.example.com/api/slow-endpoint
    # opens the Blackfire dashboard with the call graph
  5. For CI integration, use the Blackfire PHP SDK to write scenario-based tests:

    // tests/Blackfire/ApiScenario.php
    $scenario = $client->startScenario();
    $profile  = $client->assertPhpRequest($request, function ($assert) {
        $assert->metrics->sql.queries->count->isLessThan(10);
        $assert->metrics->twig.render.memory->isLessThan('2mb');
    });

Installing Tideways on Ubuntu 22.04 / PHP 8.3 FPM

  1. Install the extension from the Tideways repository:

    curl -sSL https://packages.tideways.com/key.gpg | sudo gpg --dearmor \
      -o /usr/share/keyrings/tideways.gpg
    echo "deb [signed-by=/usr/share/keyrings/tideways.gpg] \
      https://packages.tideways.com/apt-packages-main any-version main" \
      | sudo tee /etc/apt/sources.list.d/tideways.list
    sudo apt update && sudo apt install -y tideways-php tideways-daemon
  2. Configure the API key in php.ini:

    ; /etc/php/8.3/fpm/conf.d/30-tideways.ini
    extension=tideways_xhprof.so
    tideways.api_key=YOUR_KEY
    tideways.sample_rate=25
    tideways.collect=tracing
  3. Enable and start the daemon:

    sudo systemctl enable --now tideways-daemon
    sudo systemctl reload php8.3-fpm
  4. Custom spans for business-critical paths:

    $span = \Tideways\Profiler::createSpan('external_api');
    $span->startTimer();
    // ... API call ...
    $span->stopTimer();

Common pitfalls

  • Running Blackfire probe in every request. The probe is dormant unless a profiling header is present — this is intentional. If you see every request producing Blackfire data, check that blackfire.server_id and blackfire.server_token are set correctly; misconfiguration can cause the probe to activate spuriously.

  • Tideways sample_rate=100 on high-traffic sites. 100% sampling eliminates sampling bias but can add 5–10% CPU overhead at scale. Use 25 (25 samples/second) or lower for busy production workers. The Tideways UI still produces statistically valid profiles at low sample rates.

  • Both profilers and Xdebug active simultaneously. Xdebug and Blackfire are mutually exclusive at the extension level — both hook zend_execute_ex and conflict. Never load both in the same FPM pool. If you need Xdebug for local dev and Blackfire for staging, use separate PHP ini configurations per environment.

  • Missing the daemon. Both tools require a local agent/daemon process to buffer and forward profile data. If the daemon is down, the PHP extension silently drops profiles (Blackfire) or accumulates data in a local buffer that overflows (Tideways). Monitor daemon health as part of your service checks.

  • Profiling CLI queue workers with Blackfire. The on-demand trigger model does not apply to queue workers — they do not have HTTP headers. Use blackfire run php artisan queue:work --once to profile a single job, or use Tideways continuous sampling (which instruments all PHP processes automatically) for persistent queue worker monitoring.

Stack Harbor’s managed operations practice deploys Tideways as the always-on baseline for all managed PHP environments, with Blackfire available for on-demand investigation — pairing continuous visibility with the precision drill-down that on-demand profiling provides.