Guides related to Local Beach

Profiling in Local Beach using Blackfire

Blackfire provides insights into performance problems that are hard to get otherwise.

Configure Blackfire

Blackfire credentials

Add the following to the .localbeach.dist.yaml or to .env, depending on your preferences. The needed values can be taken from https://blackfire.io/docs/php/configuration after logging in to your Blackfire account.

BLACKFIRE_CLIENT_ID=…
BLACKFIRE_CLIENT_TOKEN=…
BLACKFIRE_SERVER_ID=…
BLACKFIRE_SERVER_TOKEN=…

Blackfire agent

Now edit your .localbeach.docker-compose.yaml and add this new service block for the agent (line 16 can be adjusted or left out, depending on your needs):

blackfire:
  image: blackfire/blackfire:2
  container_name: ${BEACH_PROJECT_NAME:?Please specify a Beach project name as BEACH_PROJECT_NAME}_blackfire
  depends_on:
    - php
  networks:
    - local_beach
  security_opt:
    - no-new-privileges
  environment:
    - BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID}
    - BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN}
    - BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID}
    - BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN}
    - BLACKFIRE_DISABLE_LEGACY_PORT=true
    - BLACKFIRE_LOG_LEVEL=4
  ports:
    - "8307"

Blackfire PHP probe

The probe is already part of the PHP image, so add the following to the php service block's environment section in .localbeach.docker-compose.yaml to enable it:

- BEACH_ADDON_BLACKFIRE_ENABLE=true
- BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID}
- BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN}
- BLACKFIRE_AGENT_SOCKET=tcp://${BEACH_PROJECT_NAME:?Please specify a Beach project name as BEACH_PROJECT_NAME}_blackfire:8307

Use the profiler

Now you can either profile CLI commands inside Local Beach like this:

beach exec
$ blackfire run ./flow …

Or you use the Blackfire browser extension or the CLI to start profiling your web requests…

Cover photo by Mitchel Boot on Unsplash