Symfony CLI Commands Monitoring
PHP

While it is possible to manually enable Monitoring on any CLI command, we also provide an integration allowing any Symfony commands to be traced with Blackfire Monitoring. This is particularly useful if you run them periodically, e.g., using CRON.

First, enable monitoring on your environment.

  • Add Blackfire PHP SDK as a dependency in your project (1.28+ version).
  • Enable the MonitoredCommandSubscriber in your services configuration:
1
2
# config/services.yaml
Blackfire\Bridge\Symfony\Event\MonitoredCommandSubscriber: ~

To enable tracing on a command make it implement Blackfire\Bridge\Symfony\MonitorableCommandInterface:

1
2
3
4
5
6
7
8
9
namespace App\Command;

use Blackfire\Bridge\Symfony\MonitorableCommandInterface;
use Symfony\Component\Console\Command\Command;

class MyUsefulCommand extends Command implements MonitorableCommandInterface
{
    protected static $defaultName = 'app:useful-command';
}

The PHP SDK provides an event subscriber that checks if the current command has tracing enabled. A transaction name is generated for each command based the command name. In the example above, the transaction would be named app:useful-command.

Transactions are visible on the Monitoring dashboard page, filtering on CLI requests.