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:
— Ciaran McNulty (@CiaranMcNulty) November 29, 2014
— Jan Decavele (@EpochDC) December 15, 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/
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: