Last active
June 17, 2016 08:48
-
-
Save nicolas-grekas/5c9afb79e4a8884a64a9045d54fedfe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// composer require blackfire/php-sdk | |
// search for XXX in the snippet below | |
while (isset($_SERVER['HTTP_X_BLACKFIRE_QUERY'])) { | |
$probe = \BlackfireProbe::getMainInstance(); | |
if (!$probe->disable()) { | |
break; | |
} | |
global $blackfireBuild; | |
$blackfireClient = new \Blackfire\Client(new \Blackfire\ClientConfiguration( | |
/* XXX CLIENT ID */, | |
/* XXX CLIENT TOKEN */ | |
)); | |
if (null === $blackfireBuild) { | |
$blackfireBuild = $blackfireClient->createBuild(/* XXX SERVER ID */, array( | |
'title' => 'XXX BUILD NAME', | |
)); | |
parse_str($_SERVER['HTTP_X_BLACKFIRE_QUERY'], $parts); | |
$agents = explode(',', $parts['agentIds']); | |
$mainProfileConfig = new \Blackfire\Profile\Configuration(); | |
$mainProfileConfig->setTitle('Main Request'); | |
$mainProfileConfig->setUuid(str_replace('request-id-', '', end($agents))); | |
$blackfireClient->addJobInBuild($mainProfileConfig, $blackfireBuild); | |
register_shutdown_function(function() use ($probe, $blackfireClient, $blackfireBuild) { | |
$probe->disable(); | |
$blackfireClient->endBuild($blackfireBuild); | |
$probe->enable(); | |
}); | |
} | |
$config = new \Blackfire\Profile\Configuration(); | |
$config->setSamples(1); | |
$config->setBuild($blackfireBuild); | |
$config->setTitle('Sub request to: XXX TARGET URL'); | |
$request = $blackfireClient->createRequest($config); | |
// XXX ADD BLACKFIRE REQUEST HEADER | |
// $headers['X-Blackfire-Query'] = $request->getToken(); | |
$probe->enable(); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment