KSS: How to use Blackfire to monitor the performance of PHP application
4 minutes

Sumit Shrestha
Digital Marketer

As a PHP developer, 'Blackfire' might be a name you have come across before or maybe not even heard of. For our resident PHP expert, Angel Maharjan, it was a similar case until a few months back. Even though he had 9 years of experience in PHP, Angel found Blackfire to be a revelation in his workflow.

Being such an exciting topic, it was only natural that Blackfire was scheduled into our ‘Knowledge Sharing Session’ (KSS) open to both Proshorians and IT enthusiasts outside Proshore. Read on for a grasp of what Angel shared during his one-hour workshop.

Code using too many resources?

blackfire-kss-execution-time-error
A common ‘execution time’ resource error in PHP code
blackfire-kss-memory-usage-error
A common ‘memory usage’ resource error in PHP code

PHP developers, regardless of their experience, must have come across situations like the ones presented above. The dreaded ‘error’ in terms of your application’s execution time and memory. This generally means that you,

  • go back to your code,
  • hunt down the parts utilizing the most resources, in terms of execution time and memory, and 
  • rectify the code to correct the error, which could take multiple tries.

All PHP developers will all agree that It is a tedious task to manually track which part of your code is using resources through, let’s say, microtime() or memory_get_usage() kit. The process takes up a lot of time and effort on the developer’s part lengthening the project or task delivery.

This is where Blackfire comes in. It provides a solution wherein PHP developers do not have to manually track execution time or memory usage errors in their code.

Blackfire to the rescue

Blackfire.io describes itself as a ‘Code performance observability solution’ offering the following features for your code performance, 

  • Monitoring management automation
  • Profiling
  • Testing

While Blackfire offers both paid and free features, a lot of functions are already included in the free version. Angel focused more on Blackfire’s free features in his session. He specifically talked about the profiling features of Blackfire, which provides detailed assessments of the function requests that slow down a developer’s code.

Using Blackfire’s profiler, through the browser extension or terminal, you can profile specific function requests of your app. Once Blackfire starts profiling the specific app functions, it sends multiple requests to create a bigger sample, hence, providing a more accurate analysis.

Once profiling is done, you can check the specific profiling test on your Blackfire account, analyzed in different views according to execution time and memory usage. The paid version of Blackfire includes views such as input/output time, CPU time, and more.

Profiling the problematic areas in your code

The execution time view profiles all the function calls and their execution time in inclusive and exclusive time, whereas, the memory usage view profiles all the function calls and their memory usage in both inclusive and exclusive memory.

By creating blocks of your function calls and differentiating them through nodes, colors, and borders, Blackfire profiles each function of the request and helps identify which functions are using the most resources. 

Darker the color of the block, thicker the border, or thicker the arrow helps the developer pinpoint which parts of your code are using the most reserves according to execution time or memory usage. This visual chart automatically helps developers understand which part of their code needs to be changed to optimize their application performance.

kss-php-blackfire-profiler-demo
Blackfire profile in action: Execution time view

Once you make the necessary changes to your code, after identifying them from Blackfire’s profiler or terminal, you can again profile the request to check if the functions have been optimized. You can check between current and previous profiling tests on your Blackfire account. Since each profiling test is uploaded to the Blackfire server, it is easy for developers to browse and share results even when you don’t have access to your code.

Installing Blackfire is as easy as using the platform

After making a free account with Blackfire, you generally have to download three things,

  • A language extension.
  • ‘Blackfire agent’ that needs to be installed on the operating system.
  • ‘Profiling client’ that can be installed from the browser extension or terminal.

With these in place, you can start monitoring your PHP application’s performance right away!

We hope that the KSS summary above gives you an idea of what Blackfire is and how you, as a PHP developer or even Python or GO Developer, can use the free features to monitor your application’s performance. 

During his one-hour workshop, Angel used an open-source project from GitHub to demonstrate Blackfire’s profiling features and installation in action. You too can get access to the workshop recording and see Blackfire in action.

6 minutes

Extra Capacity: 6 Ways To Work Well With Remote Teams

It’s no secret that using offshore developers and remote teams is a cost-effective way for software companies to add extra capacity and accelerate production. Not only does it help reduce…
Haico Duisters
Managing Director
6 minutes

How we built a Powerful and Customizable Dashboard for a Market-Research SaaS

Let’s say you’re looking for a front-end team who can handle a complex and customizable customer-facing dashboard in Angular. Finding the right tech talent locally might be a challenge. But…
Atul Shrestha
Web Developer
6 minutes

Proshore Bootcamp: More than a mentorship program

Proshore Bootcamp was born out of love for two things: IT and Nepal. As part of Proshore’s social mission to create better job opportunities for aspiring IT professionals working in…
Sumit Shrestha
Digital Marketer