Starting in version 1.14.0, a build can contain multiple scenarios. This changed the way builds are structured and initialized.
Deprecated items:
- Class
\Blackfire\Build (replaced by \Blackfire\Build\Scenario) - Methods
createBuild, endBuild, and addJobInBuild (replaced by startScenario, closeScenario, and addJobInScenario)
New items:
- Classes
\Blackfire\Build\Build and \Blackfire\Build\Scenario - Methods
startBuild, closeBuild, startScenario, closeScenario, and addJobInScenario
Migration Example:
From the legacy single-scenario approach:
$build = $blackfire->createBuild('Blackfire dev', array('title' => 'Legacy build'));
$config = new \Blackfire\Profile\Configuration();
$config->setBuild($build);
$probe = $blackfire->createProbe($config);
// ... profile code ...
$blackfire->endProbe($probe);
$report = $blackfire->endBuild($build);
To the new multi-scenario approach:
$build = $blackfire->startBuild('Blackfire dev', array('title' => 'My build'));
$scenario = $blackfire->startScenario($build, array('title' => 'Test documentation'));
$config = new \Blackfire\Profile\Configuration();
$config->setScenario($scenario);
$probe = $blackfire->createProbe($config);
// ... profile code ...
$blackfire->endProbe($probe);
$report = $blackfire->closeScenario($scenario);
$blackfire->closeBuild($build);
<?php
require_once __DIR__.'/vendor/autoload.php';
$blackfire = new /Blackfire/Client();
// create a build
$build = $blackfire->startBuild('Blackfire dev', array(
'title' => 'My build',
'trigger_name' => 'PHP',
));
// create a scenario
$scenario = $blackfire->startScenario($build, array(
'title' => 'Test documentation',
'external_id' => 'c:my-scenario',
'external_parent_id' => 'b:my-scenario',
));
// create a configuration
$config = new /Blackfire/Profile/Configuration();
$config->setScenario($scenario);
// create as many profiles as you need
$probe = $blackfire->createProbe($config);
// some PHP code you want to profile
echo strlen('Hello !');
$blackfire->endProbe($probe);
// end the build and fetch the report
$report = $blackfire->closeScenario($scenario);
$blackfire->closeBuild($build);