Platform.sh recommends Blackfire.io. Blackfire is a full continuous observability solution (monitoring, profiling, and automated performance testing tool). It can be used on Integration, Staging, and Production environments. Blackfire supports PHP and Python.

It grants details information on your PHP code’s resources consumption across Wall-Time, CPU, I/O, Memory, Network Calls, HTTP requests and SQL queries.

In addition, it can profile your code automatically and notify you whenever your code does not comply with best practices for PHP, Symfony, Drupal, eZPlatform, Typo3 & Magento code performance management.

For a high level overview and demo of Blackfire, check out the full video tutorial.

Version 

Check the latest versions of the probe and CLI tool on Blackfire’s documentation.

On a Grid plan 

1. Get your credentials 

Sign up for the free 15 days Premium trial at Blackfire.io and install the Blackfire Companion web browser extension (Chrome or Firefox).

Go to your Dashboard and create a new environment under the Environments tab.

Blackfire environments

2. Enable Blackfire 

Follow the step-by-step instructions to enable Blackfire on your PHP or Python applications.

On a Dedicated cluster 

Sign up for the free 15 days Premium trial at blackfire.io and install the Blackfire Companion web browser extension (Chrome or Firefox).

Dedicated Generation 3 

Define new Project Variables with your Blackfire Server ID, Server Token, Client ID and Client Token.

env:BLACKFIRE_SERVER_ID = ...
env:BLACKFIRE_SERVER_TOKEN = ...
env:BLACKFIRE_CLIENT_ID = ...
env:BLACKFIRE_CLIENT_TOKEN = ...

Other Dedicated Infrastructure 

Open a support ticket with the Backfire Server ID, Server Token, Client ID, Client Token. Our support team will install it for you.

Note, Blackfire integration works only on profiling your cluster via the URL to the origin. Do not profile your site going through the CDN.

Profiling web requests 

Access your site via your browser and click Profile in the Blackfire Companion.

Blackfire Companion

That’s it! Your site will be profiled and you should get all the results in your Blackfire account.

Profiling CLI commands 

To profile your PHP CLI scripts, use the following command line:

blackfire --config /etc/platform/$USER/blackfire.ini <command>

Going further with Blackfire 

Blackfire also enables you to:

Check Blackfire’s documentation for more information.

Enable Blackfire Monitoring 

Blackfire Monitoring is enabled by default for Monitoring customers.

To disable Blackfire Monitoring, you will need to add the BLACKFIRE_APM_ENABLED environment variable with a value of 0.

In the management console, view the environment you would like to disable Blackfire Monitoring on and add the variable env:BLACKFIRE_APM_ENABLED with the value 0. Otherwise, you can use the CLI command platform variable:create --level environment --name BLACKFIRE_APM_ENABLED --value 0

Troubleshooting 

Bypassing Reverse Proxy, Cache, and Content Delivery Networks (CDN) 

If you are using one of those, you will need them to let Blackfire access your servers. More information on how to configure a bypass.

HTTP Cache configuration 

If you are using the HTTP cache with cookies , please update in your .platform/routes.yaml the cookies that are allowed to go through the cache. You need to allow the __blackfire cookie name.

Something like:

cache:
    enabled: true
    cookies: ["/SESS.*/", "__blackfire"]

Reaching out to the Blackfire support 

If the above didn’t help, collect the following and send it to the Blackfire support:

  • The output of platform ssh -- php -d display_startup_errors=on --ri blackfire command
  • The Blackfire logs

Getting the Blackfire logs 

Please execute the following in the environment where you’re facing the issue:

  • platform variable:create php:blackfire.log_file --value /tmp/blackfire.log
  • platform variable:create php:blackfire.log_level --value 4
  • start a profile/build again

You will get the logs with platform ssh -- cat /tmp/blackfire.log > blackfire.log.

Disabling the Blackfire logs 

Once you are done, please disable logging with:

  • platform variable:delete php:blackfire.log_file
  • platform variable:delete php:blackfire.log_level