KSS: How to use Blackfire to monitor performance in 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

Staff augmentation vs project outsourcing – what’s right for your company’s IT needs?

There’s more than one way to expand your IT capabilities. Two approaches stand out from the pack: staff augmentation and project outsourcing.
Customer Success
Team
4 minutes

10 benefits of IT staff augmentation

If your dev team is up against an endless product backlog that never seems to shrink, you might be ready to benefit from staff augmentation.
Customer Success
Team
4 minutes

The benefits of Laravel for CRM Development

From scalability and security to performance and developer productivity, discover the unparalleled benefits of using Laravel for CRM development.
Customer Success
Team