John Davidson

Problem running Blackfire together with PHP Swoole in Docker

0 comments
Message:


Has anyone managed to use Blackfire together with Swoole? I've been trying to set it up for a few days, but without success.


I'm calling the following script in the PHP-CLI Swoole Dockerfile:


#!/usr/bin/env bash

# @see https://blackfire.io/docs/up-and-running/installation

set -e

apt-get update
apt-get install -y gnupg --no-install-recommends

# Configure the Debian Repository
wget -q -O - https://packages.blackfire.io/gpg.key | apt-key add -
echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list
apt-get update

# Install and Configure the Agent
echo "$(date '+%Y-%m-%d %H:%M:%S,%3N') $(tput bold)$(tput setaf 4)INFO$(tput sgr0) Install and Configure the Agent."
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install blackfire
blackfire agent:config --server-id=MY-SERVER-ID --server-token=MY-SERVER-TOKEN
/etc/init.d/blackfire-agent restart

# Install the PHP Probe
echo "$(date '+%Y-%m-%d %H:%M:%S,%3N') $(tput bold)$(tput setaf 4)INFO$(tput sgr0) Install the PHP Probe."
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install blackfire-php

# Clear
rm -r /var/lib/apt/lists/*
mkdir -p /var/run/blackfire

supervisor conf:


[supervisord]
user = root

[program:blackfire-agent]
command = /usr/bin/blackfire agent:config --server-id=MY_BLACKFIRE_SERVER_ID --server-
token=MY_BLACKFIRE_SERVER_TOKEN
user = root
autostart = true
autorestart = true
stdout_logfile = /proc/self/fd/1
stdout_logfile_maxbytes = 0
stderr_logfile = /proc/self/fd/1
stderr_logfile_maxbytes = 0

Error msg on use blackfire curl:


reginato@reginato-Lenovo-IdeaPad-S145-15IWL:~/git/shark-tank$ docker-compose exec blackfire blackfire curl http://localhost:9501

WARNING: Some services (elk, redis) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.

20/06 00:19:26 DEBUG blackfire Reading client configuration file "/dev/null"
20/06 00:19:26 DEBUG blackfire Retrieving signature
20/06 00:19:26 DEBUG blackfire Sending request GET https://blackfire.io/api/v1/collab-tokens
20/06 00:19:28 DEBUG blackfire Sending request POST https://blackfire.io/api/v1/signing
20/06 00:19:28 DEBUG blackfire Fetching agent credentials
20/06 00:19:28 DEBUG blackfire Sending request GET https://blackfire.io/api/v1/agents
20/06 00:19:28 DEBUG blackfire Timespan enabled, launching preflight.

20/06 00:19:28 DEBUG blackfire #################] 100%
Error while running command: exit status 7


My Answer:
Dockerfile
FROM php:7.4-cli

# Install Blackfire
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \
&& mv /tmp/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& echo "extension=blackfire.so" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm /tmp/blackfire-probe.tar.gz

# Install Swoole
RUN pecl install swoole && docker-php-ext-enable swoole

CMD ["php", "-S", "0.0.0.0:8000"]


Make sure to replace `PHP_MAJOR_VERSION` and `PHP_MINOR_VERSION` with the appropriate values for your PHP version. Also, ensure that you have the necessary permissions to install extensions in your Docker container.

After building and running your Docker container, you should be able to use Blackfire together with Swoole. Let me know if you encounter any issues.

Rate this post

3 of 5 based on 5047 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us