Blackfire lets you profile HTTP requests like web pages, web service calls, or API calls.
To get started, check that you have Blackfire installed correctly on the server hosting the website you want to profile.
Profiling an HTTP request means instrumenting the project’s code. Blackfire is apart from many other profilers because of two main differences:
This cookbook describes how to profile from the command line interface. You can also profile web applications from a browser.
Profiling an HTTP request can be done on the command line thanks to the
blackfire
utility.
The easiest way to profile an HTTP request is to use the curl
sub-command
of the blackfire
utility. It accepts the same arguments and options as the regular curl
utility:
1 | blackfire curl http://example.com/ |
Warning
CLI profiling relies on BLACKFIRE_CLIENT_ID
and BLACKFIRE_CLIENT_TOKEN
,
your personal credentials. Only the user whose
credentials are used can access those profiles from /my/profiles.
Please consider adding the --env=<ENV_UUID>
parameter to send the profile
to a shared environment and permit
collaboration.
You can get a list of options available for the curl
sub-command:
1 | blackfire help curl |
To get more accurate results, take several samples of the request via the
--samples
option (we recommend you to use this option only for “safe” HTTP
requests like GET
requests):
1 | blackfire --samples 10 curl http://example.com/ |
At the end of the request, blackfire
outputs the URL where the profile can
be found (hide it by passing the -q
option.)
You can integrate Blackfire results into your tools by using the --json
option to get a JSON representation of a profile:
1 | blackfire --json curl http://example.com/ |
Note
The JSON output is displayed on STDOUT
, while the regular output (e.g.
progress, profile summary…) is displayed on STDERR
.
The resources consumed are available under the envelope
entry;
keys are the cost dimensions:
Profiling non-GET requests or requests which need some specific HTTP headers is
no different as blackfire curl
supports all cURL options:
1 | blackfire curl -XPOST http://example.com/ |
Blackfire automatically instruments your code, but sometimes, you might want to focus the profiling on only part of the code. That’s possible when opting for manual instrumentation via the PHP SDK.
After instrumenting your code, use the blackfire
utility as above to
profile your application. When not using Blackfire, all calls are converted to
no-ops.
Profiling POST requests, Ajax requests, and API calls can be done via the “Profile all Requests” link in the browser extension.
When profiling from a browser, select “Profile all requests”, then “Record!”. Blackfire will instrument all requests until you click on the “Stop” button in the pop-over.
A pop-over window will open at the bottom right of your screen, where all profiled requests will be listed.
All PHP requests which have been profiled will be shown on your dashboard.