WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.066 --> 00:00:04.776 align:middle
We know that the probe - that's
the Blackfire PHP extension -

00:00:05.006 --> 00:00:09.606 align:middle
doesn't run on every single
request: it only runs when it detects

00:00:09.606 --> 00:00:12.886 align:middle
that our browser extension is telling it to run.

00:00:13.496 --> 00:00:18.026 align:middle
There's actually a second way that
you can tell the probe to do its work.

00:00:18.396 --> 00:00:20.676 align:middle
It's with a super handy command-line tool.

00:00:21.886 --> 00:00:25.266 align:middle
Go back to the Blackfire
site, click on their docs...

00:00:25.566 --> 00:00:28.156 align:middle
and once again find the installation page.

00:00:28.966 --> 00:00:33.366 align:middle
When we went through this earlier,
we purposely skipped one step:

00:00:33.956 --> 00:00:36.686 align:middle
installing the Blackfire CLI tool.

00:00:37.096 --> 00:00:40.276 align:middle
Actually, Blackfire recently
updated this page...

00:00:40.346 --> 00:00:42.626 align:middle
and I like the newer version a lot better.

00:00:43.326 --> 00:00:47.976 align:middle
In both versions of the docs - the
new one and the old one you see here -

00:00:47.976 --> 00:00:51.176 align:middle
if you followed the commands to install the

00:00:51.176 --> 00:00:55.656 align:middle
"agent" then you've already
also installed the CLI tool.

00:00:56.056 --> 00:01:02.556 align:middle
Nice! To make sure, find your terminal
and try running: blackfire version Got it!

00:01:03.516 --> 00:01:07.636 align:middle
Before using this, we do need to
add a little bit of configuration

00:01:07.916 --> 00:01:10.786 align:middle
by running a blackfire config command.

00:01:11.636 --> 00:01:17.036 align:middle
On the old version of the docs, I'll copy
the "client ID": I'll need that in a second.

00:01:17.696 --> 00:01:23.056 align:middle
On the newer version of the docs, you'll
be able to copy a blackfire config command

00:01:23.166 --> 00:01:27.006 align:middle
that already includes the
client id and client token.

00:01:27.006 --> 00:01:33.716 align:middle
For me, I'll run blackfire config If
your version of the command has the --

00:01:33.826 --> 00:01:39.926 align:middle
client-id and -- client-token
options already, you're done!

00:01:39.926 --> 00:01:43.676 align:middle
If not, like me, paste in the Client Id...

00:01:44.126 --> 00:01:46.816 align:middle
then also copy and paste in the token.

00:01:48.226 --> 00:01:50.046 align:middle
The client id and token work...

00:01:50.416 --> 00:01:54.556 align:middle
almost like a username and
password to your Blackfire account.

00:01:55.806 --> 00:02:00.816 align:middle
When we use the browser extension, we're
logged into Blackfire in the browser.

00:02:01.426 --> 00:02:07.156 align:middle
When we click profile, the Blackfire API is
able to give the extension some credentials

00:02:07.506 --> 00:02:12.516 align:middle
that it passes to the probe to prove
that we're allowed to profile this page.

00:02:13.446 --> 00:02:16.826 align:middle
When you use the Blackfire command
line tool to profile something...

00:02:17.266 --> 00:02:21.496 align:middle
the client id and client token are
used to talk to the Blackfire API

00:02:21.496 --> 00:02:25.986 align:middle
and get those same credentials
that it then passes to the probe

00:02:25.986 --> 00:02:28.126 align:middle
to prove we're authorized to profile.

00:02:28.696 --> 00:02:33.276 align:middle
They basically identify &amp; prove
which user we are on Blackfire.

00:02:33.966 --> 00:02:36.816 align:middle
The Blackfire CLI tool has two superpowers.

00:02:37.396 --> 00:02:44.046 align:middle
The first is that you can run blackfire curl
and then pass a URL to any page on your site

00:02:44.046 --> 00:02:46.546 align:middle
that you want to create a profile for.

00:02:47.536 --> 00:02:51.376 align:middle
Now... that might seem totally worthless.

00:02:51.836 --> 00:02:52.546 align:middle
After all...

00:02:52.696 --> 00:02:54.246 align:middle
if we want to profile a page...

00:02:54.376 --> 00:02:59.846 align:middle
isn't it easier just to go to that page in our
browser and use the extension to profile it?

00:03:00.456 --> 00:03:02.196 align:middle
Yep! Unless...

00:03:02.396 --> 00:03:06.946 align:middle
you can't easily "go" to
that page - like if you want

00:03:06.946 --> 00:03:11.026 align:middle
to profile an AJAX request or an API endpoint.

00:03:11.906 --> 00:03:17.456 align:middle
Check this out: I'll open up the dev tools,
go to the "Network" section and refresh.

00:03:19.056 --> 00:03:22.506 align:middle
Notice I'm already filtered to XHR requests -

00:03:22.736 --> 00:03:27.426 align:middle
so the /api/github-organization
AJAX request pops up.

00:03:28.316 --> 00:03:31.236 align:middle
Want to easily profile just that request?

00:03:31.976 --> 00:03:34.906 align:middle
Right click on it and select "Copy as cURL".

00:03:37.556 --> 00:03:39.986 align:middle
Now head back to your terminal and paste.

00:03:41.166 --> 00:03:41.936 align:middle
Cool, right?

00:03:42.716 --> 00:03:47.636 align:middle
It creates a full curl command that you
can use to make that same request...

00:03:47.896 --> 00:03:53.796 align:middle
including any session cookies, which
means this request will be authenticated

00:03:53.796 --> 00:03:56.896 align:middle
as the same user you're logged
in as in the browser.

00:03:58.196 --> 00:04:03.026 align:middle
We can use this with Blackfire:
say blackfire then paste!

00:04:03.796 --> 00:04:08.966 align:middle
Try it! It's profiling and using
the same process as the browser:

00:04:09.366 --> 00:04:11.936 align:middle
making 10 requests and profiling each one.

00:04:12.496 --> 00:04:16.826 align:middle
This is my favorite way to
profile AJAX requests.

00:04:16.826 --> 00:04:21.906 align:middle
When it finishes, it gives us the URL to
the call graph and some basic stats below.

00:04:22.336 --> 00:04:28.726 align:middle
Go open that profile: http://bit.ly/sf-bf-curl!

00:04:28.726 --> 00:04:32.636 align:middle
It works! Use that to easily profile
any AJAX requests you want to.

00:04:33.406 --> 00:04:36.656 align:middle
So what is the second superpower
of the CLI tool?

00:04:37.406 --> 00:04:42.956 align:middle
It's actually its main superpower: the
ability to profile command-line scripts.

00:04:43.316 --> 00:04:44.896 align:middle
Let's do that next.

