Profile all the things
Blackfire started by providing an easy way to profile web pages. Today, we introduce new ways to easily profile CLI scripts and API or web services calls.
Since day one, our main goal with Blackfire has been to ease profiling web applications as much as possible. Developers should profile their applications more than they are doing; and when they do, it pays off big-time:
20 mins with @blackfireio and I’ve spotted a reasonably quick win that should take 10% off @phpspec‘s execution time. This tool’s amazing
— Ciaran McNulty (@CiaranMcNulty) November 29, 2014
Just killed a huge bottleneck with #Blackfireio ! — Fabien Bourigault (@fbourigault) December 9, 2014
@blackfireio after a quick profile I was able to quadruple a legacy apps performance in an hour’s worth of coding. Thank you #blackfireio !!
— Jan Decavele (@EpochDC) December 15, 2014
Another 700ms gone using @blackfireio 😉 — markus staab (@markusstaab) December 10, 2014
But nowadays, web applications are not just about web pages in a browser anymore; most web applications also expose APIs or web services and they come with CLI scripts. And today, I’m very excited to announce a new utility to ease profiling this non-browsable code.
Before trying the following examples, upgrade the Blackfire packages to the latest versions we’ve released earlier today.
Profiling CLI Scripts
Profiling a CLI script is now as easy as it can get:
$ blackfire run ./some/script.php $ blackfire run php ./some/script.php
That’s right, just prefix your command with blackfire run
and you’re good to go! By default, it asks for the slot you want the profile to be stored in and displays the URL where you can view the profile at the end of the execution. You can also make the command non-interactive and quiet:
$ blackfire -q --slot=7 run ./some/script.php
Read the Profile CLI scripts documentation for more information.
Profiling APIs and Web Services
One of the most frequently asked features so far for Blackfire is the ability to profile web services and API calls. If you are already using cURL to test your calls, profiling them is again very easy:
$ blackfire curl http://symfony.com/
Prefix your cURL command with blackfire
and profiling will be automatically activated. You can also make everything quiet and non-interactive:
$ blackfire -q --slot=7 curl http://symfony.com/
If you want to use wget, the excellent HTTPie utility, or your own script, read the Profile API /Web Services calls documentation as it explains how everything works behind the scenes.
Profiling Web Pages from the CLI
As you might have guessed already, you can use the blackfire curl
command to profile your regular web pages as well… and that’s the first step towards automation, but that’s for another day!
Let me finish with a great tip: modern browsers have a “copy as cURL” feature that comes in very handy for more “complex” web pages like POST
request on a form:
Happy profiling!