BlackFire PHP monitoring and testing tool

NHAILA Achraf
5 min readNov 16, 2022

Blackfire: Everything you need to know about the star PHP monitoring and testing tool

What is Blackfire?

Blackfire is a SaaS (Software as a Service) suite designed to perform automated testing and continuous monitoring of PHP applications. Published by the French company of the same name, it goes as far as collecting data specific to resources consumed on production servers. It provides valuable information such as input/output operations, processor response time and memory used. In concrete terms, its use helps optimize application performance.

The main features dedicated to DevOps are:

Continuous testing and monitoring;
Graphical visualization of code iterations;
Bottleneck detection,
Real-time application performance management (APM).

Blackfire’s offer is based on two bricks:

Blackfire Monitoring and Blackfire Profiler.

How to install Blackfire?

The installation and configuration of Blackfire is done in four steps:

The installation of the tool itself;
The creation of an agent on the dedicated server;
The configuration of Blackfire;
Debugging web pages with the integration of a probe.

For more information, SensioLabs offers a complete tutorial on its official blog.

Why using Blackfire on Production Servers
On production servers, Blackfire is complementary to the monitoring system you already have in place. It allows you to:

Identify the root causes of performance issues; (Gain Time To Debug for any problems on code or tiers services communications, CLI cron can also been profiled)
Understand how your code behaves under stress; (Can only be seen on production with natural trafic)
Find security issues even if no code changed (new vulnerabilities discovered in PHP for instance).

BLACKFIRE

Source : https://blackfire.io/docs/book/24-another-look#using-blackfire-on-production-servers

2/ How it needs to be installed :

https://blackfire.io/docs/book/06-installation#installation-on-staging-testing-and-production

https://blackfire.io/docs/integrations/docker/index

3/ How we did install and secure the natural trafic :

BlackFire PHP monitoring and testing tool

Blackfire: Everything you need to know about the star PHP monitoring and testing tool

The main features dedicated to DevOps are:

Continuous testing and monitoring;
Graphical visualization of code iterations;
Bottleneck detection,
Real-time application performance management (APM).

How to install Blackfire?

The installation and configuration of Blackfire is done in four steps:

The installation of the tool itself;
The creation of an agent on the dedicated server;
The configuration of Blackfire;
Debugging web pages with the integration of a probe.

For more information, SensioLabs offers a complete tutorial on its official blog.

Why using Blackfire on Production Servers
On production servers, Blackfire is complementary to the monitoring system you already have in place. It allows you to:

Identify the root causes of performance issues; (Gain Time To Debug for any problems on code or tiers services communications, CLI cron can also been profiled)
Understand how your code behaves under stress; (Can only be seen on production with natural trafic)
Find security issues even if no code changed (new vulnerabilities discovered in PHP for instance).

BLACKFIRE

Source : https://blackfire.io/docs/book/24-another-look#using-blackfire-on-production-servers

2/ How it needs to be installed :

https://blackfire.io/docs/book/06-installation#installation-on-staging-testing-and-production

https://blackfire.io/docs/integrations/docker/index

3/ How we did install and secure the natural trafic :

Dedicated fpm blackfire
we are using a specifc pod fpm in order to not distrub the public trafic

4/ Limit memory on blackfire fpm pod to avoid memory crash on host node

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 mean instrumenting the project’s code. Blackfire is apart from many other profilers because of two main differences:

  • Blackfire automatically instruments your code when needed, so you don’t need to change your code;
  • Blackfire does nothing when you are not profiling a request (the overhead is then almost zero), so it is safe to deploy Blackfire on production servers, even for heavy-traffic projects.

4/ Limit memory on blackfire fpm pod to avoid memory crash on host node

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 mean instrumenting the project’s code. Blackfire is apart from many other profilers because of two main differences:

  • Blackfire automatically instruments your code when needed, so you don’t need to change your code;
  • Blackfire does nothing when you are not profiling a request (the overhead is then almost zero), so it is safe to deploy Blackfire on production servers, even for heavy-traffic projects.

This cookbook describes how to profile from the command line interface. You can also profile web applications from a browser.

Profiling Simple HTTP Requests

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:

blackfire curl http://example.com/

You can get a list of options available for the curl sub-command:

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):

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.)

Profiling without cURL

Note that you need curl to be installed on your system for blackfire curl to work. If curl is not available or if you prefer to use another tool to make your HTTP requests, use the run sub-command instead:

--

--