Blackfire Install: Agent, Probe, Chrome Extension

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

So let's get Blackfire installed on our local computer. Head over to https://blackfire.io and log in or register for a new account. As you can see, I've been busy using Blackfire already.

Agent & Probe: How it all Works

Click the Docs link on top... then installation on the left. Before we jump in and install everything, I want you to understand just a little bit about how this all works: understanding this helped me a bunch. If you want to skip this and head to the next video you can... just prepare to miss out on some cool diagrams!

Click the "main components of Blackfire" link and scroll down to find... woh! A diagram that shows you exactly how Blackfire works.

The Probe: PHP Extension that Collects Data

How about... we look at a simplified version. There are 3 things we need to install. The first is called the "probe", which is really just a PHP extension. You'll install this wherever your code is running - like on your local machine, and later on production. The probe's job is simple, but huge! It's responsible for collecting all of the information: all the function calls, how long each took, which function called which other function, how much memory did something take, network requests... you get the idea. By the way, the process of "collecting all the data" is sometimes called instrumentation... which I only mention so that if you see this fancy word... it hopefully won't confuse you... it confused me.

The Probe: Collector and Sender

The second thing we will need to install is called the "agent". This is a service - or "daemon" - that runs on your computer - or on your production machine. It... just sits there and waits. When the PHP extension - the probe - finishes collecting all the data, it sends that data to the agent. The agent does some processing on it - like removing unimportant information and anonymizing things - then ultimately sends that data to the Blackfire server. It's... the middleman.

So basically, the probe and agent work together to collect the info and send it to Blackfire.

The Browser Extension: Profiling Activator

The last piece you'll need to install is a browser extension. Remember: the probe is not profiling every single request. Normally, when a request comes in, it yawns... and does nothing. The browser extension's job is to activate profiling. It basically says:

Hey probe! Wake up! I'm going to make a request and I actually want you to do your thing - collect all the data and sent it to the agent. Cool? Text me when it's done.

And... that's it! This bottleneck-fighting superhero trio is our ticket to performance glory. Next, let's get them installed.

Leave a comment!

This tutorial can be used to learn how to profile any app - including Symfony 5.

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "blackfire/php-sdk": "^1.20", // v1.20.0
        "sensio/framework-extra-bundle": "^5.4", // v5.5.1
        "symfony/console": "4.3.*", // v4.3.10
        "symfony/dotenv": "4.3.*", // v4.3.10
        "symfony/flex": "^1.3.1", // v1.6.0
        "symfony/form": "4.3.*", // v4.3.10
        "symfony/framework-bundle": "4.3.*", // v4.3.9
        "symfony/http-client": "4.3.*", // v4.3.10
        "symfony/orm-pack": "^1.0", // v1.0.7
        "symfony/security-bundle": "4.3.*", // v4.3.10
        "symfony/serializer-pack": "^1.0", // v1.0.2
        "symfony/twig-bundle": "4.3.*", // v4.3.10
        "symfony/validator": "4.3.*", // v4.3.10
        "symfony/webpack-encore-bundle": "^1.6", // v1.7.2
        "symfony/yaml": "4.3.*", // v4.3.10
        "twig/extensions": "^1.5" // v1.5.4
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.2", // 3.2.2
        "fzaninotto/faker": "^1.8", // v1.8.0
        "symfony/debug-pack": "^1.0", // v1.0.7
        "symfony/maker-bundle": "^1.13", // v1.14.3
        "symfony/test-pack": "^1.0" // v1.0.6
    }
}