Goutte is a screen scraping and web crawling library for PHP. Integrating Blackfire with Goutte lets you profile programmatically your websites, HTTP APIs, or web services.
First, add Blackfire PHP SDK as a dependency on your project and be sure to require Goutte as well:
1
composer require fabpot/goutte
To profile with Goutte, add the X-Blackfire-Query HTTP header before doing
any HTTP request you want to profile with Blackfire:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
use Goutte\Client as GoutteClient;
use Blackfire\Client as BlackfireClient;
$blackfire = new BlackfireClient();
$client = new GoutteClient();
// as we want to profile the next request, add the Blackfire header
$profileRequest = $blackfire->createRequest('Blog Home');
$client->setHeader('X-Blackfire-Query', $profileRequest->getToken());
$crawler = $client->request('GET', 'https://www.symfony.com/blog/');
// get the profile for the request
$profile = $blackfire->getProfile($profileRequest->getUuid());
$link = $crawler->selectLink('Security Advisories')->link();
// also works before clicking on a link or submitting a form
$client->setHeader('X-Blackfire-Query', $blackfire->createRequest('Security Advisories')->getToken());
$crawler = $client->click($link);
Never re-use a token for different HTTP requests.
If you execute this script, two profiles will be created on your Blackfire
account (tests defined in .blackfire.yaml will be executed as well if any).
Learn more about profiling configuration settings in the PHP SDK documentation.