Profiling with Blackfire for WordPress

Setup Blackfire profiling tool on your local machine ( I’m installing it on Windows ). Profiling help developer to analyse there coding performance. Find unwanted calls / memory issues and helps to optimize all the possible issues.

# Setup Blackfire Environment

Follow below 10 steps to setup Blackfire on Windows system. For other system setup goto https://blackfire.io/


Step 1) Download Binary Files

Download 32 Bit Binary file
Download 64 Bit Binary file

For latest binary files goto – Blackfire Installation


Step 2) Create Blackfire directory in your system.

I’m creating it like C:\Program Files\Blackfire.


Step 3) Set Windows PATH environment variable.

You can set it though Command Prompt ( CMD ) OR though windows Edit System Environment.
I’m using command prompt.

So, I follow below steps:

- Add though 'Command Prompt ( CMD )'
- Open Command Prompt by pressing `( Windows + R )` key. Or Goto start menu and search `command prompt`.
- Add command set PATH=%PATH%;C:\Program Files\Blackfire - NOTE: Add location where you extract the Blackfire binary files.

Add below command and confirm the system path is perfectly set.

echo %path%

Step 4) Create ‘agent.ini’ like ‘C:\Program Files\Blackfire\agent.ini’. And add below code.

Note: Please add your MY_SERVER_ID & MY_SERVER_TOKEN which you get it after login / register to http://blackfire.io

Or

Avoid below step. Goto Blackfire Configure

Here, Blackfire auto generate your agent.ini with your MY_SERVER_ID & MY_SERVER_TOKEN.

[blackfire]
;
; setting: ca-cert
; desc   : Sets the PEM encoded certificates
; default:
ca-cert=

;
; setting: collector
; desc   : Sets the URL of Blackfire's data collector
; default: https://blackfire.io
collector=https://blackfire.io/

;
; setting: log-file
; desc   : Sets the path of the log file. Use stderr to log to stderr
; default: stderr
log-file=stderr

;
; setting: log-level
; desc   : log verbosity level (4: debug, 3: info, 2: warning, 1: error)
; default: 1
log-level=1

;
; setting: server-id
; desc   : Sets the server id used to authenticate with Blackfire API
; default:
server-id=[MY_SERVER_ID]

;
; setting: server-token
; desc   : Sets the server token used to authenticate with Blackfire API. It is unsafe to set this from the command line
; default:
server-token=[MY_SERVER_TOKEN]

;
; setting: socket
; desc   : Sets the socket the agent should read traces from. Possible value can be a unix socket or a TCP address
; default: unix:///var/run/blackfire/agent.sock on Linux, unix:///usr/local/var/run/blackfire-agent.sock on MacOSX, and tcp://127.0.0.1:8307 on Windows.
socket=unix:///var/run/blackfire/agent.sock

;
; setting: spec
; desc   : Sets the path to the json specifications file
; default:
spec=

Step 5) Goto ‘Command Prompt’ and add below commands:

cd C:
cd C:\Program Files\Blackfire\
blackfire-agent -register

Add your Server Id & Server Token which you get from http://blackfire.io

blackfire config

Add your Server Id & Server Token which you get from http://blackfire.io


Step 6) Download PHP ‘.dll’ file for blackfire and rename with ‘php_blackfire.dll’.
You can download it by your system & PHP version.

E.g.
Download 32 Bit & PHP 7
Download 32 Bit & PHP 7

Or

Download appropriate PHP ‘.dll’ from Blackfire Get Dll


Step 7) Goto PHP extensions directory. I have it in ‘C:\xampp\php\ext\’. And move downloaded ‘php_blackfire.dll’ within it.


Step 8) Open ‘php.ini’ file and add below code:

Note: If you have ‘XDebug’ or ‘XHProf’ then disable these.

[blackfire]
extension=blackfire.so
; On Windows use the following configuration:
extension=php_blackfire.dll


; Sets the socket where the agent is listening.
; Possible value can be a unix socket or a TCP address.
; Defaults to unix:///var/run/blackfire/agent.sock on Linux,
; unix:///usr/local/var/run/blackfire-agent.sock on MacOSX,
; and to tcp://127.0.0.1:8307 on Windows.
;blackfire.agent_socket = unix:///var/run/blackfire/agent.sock

blackfire.agent_timeout = 0.25

; Log verbosity level (4: debug, 3: info, 2: warning, 1: error)
;blackfire.log_level = 1

; Log file (STDERR by default)
;blackfire.log_file = /tmp/blackfire.log

;blackfire.server_id =

;blackfire.server_token =

Step 9) Open ‘.htaccess’ file in which local site you want to test the blackfire and add below code:

Note: Add your Server ID & Server Token.

    php_admin_value blackfire.server_id "[MY_SERVER_ID]"
    php_admin_value blackfire.server_token "[MY_SERVER_TOKEN]"

Step 10) Download blackfire chrome extension from Download Blackfire Chrome


Step 11) Goto – ‘C:\Program Files\Blackfire’ and execute blackfire-agent.exe.

It open the black window. KEEP THIS WINDOW AS IT IS. Minimize it. ( DON’T CLOSE IT ).

Its done. Lets test it.

  • Goto the local website in which ‘.htaccess’ you added blackfire.

  • I have http://localhost/dev.themes/ – Click on installed chrome extension icon from top right. – And click on ‘Profile’ button.


# Analyse Profiling Result

Goto your Blackfire dashboard and analyse your blackfire profiling result. Click here for depth analyzing profiles

E.g.

 

 

Advertisements

Author: maheshwaghmare

WordPress Developer since 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s