我正在使用一个简单的基于 Docker 的 PHP 应用程序(https://github.com/fuhrysteve/php-docker-apache-example.git)来演示Blackfirekfire 分析:
1. 为 BlackFire 安装 Chrome 扩展程序(在 chrome 上)
2.定义这些环境变量:
$export BLACKFIRE_CLIENT_ID=921b5dfa-a9e0-4979-8bd1-a7a7a2acf031
$export BLACKFIRE_CLIENT_TOKEN=af050bfc9cf3761082828e3f5e4f31ada89649f0635c0cb445c86f26f72a8e18
$export BLACKFIRE_SERVER_ID=3534d1d9-7c0b-4c5b-9aad-eda497b27494
$export BLACKFIRE_SERVER_TOKEN=79082e6b82122630d6be03bb8f3f8c9544fadada78156ef4606d86f639644eb0
3.安装代理
docker run --name="blackfire" -d -e BLACKFIRE_SERVER_ID -e BLACKFIRE_SERVER_TOKEN blackfire/blackfire
4. 启用 PHP 探针
$cat Dockerfile
FROM php:7.0-apache
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 \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://myapp:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
RUN apt-get update && \
#apt-get install -y php5-mysql && \
apt-get clean
COPY myapp /var/www/html/
5. 构建 myapp 容器
$docker build -t php-docker-apache-example
。
6. Docker 运行
$docker network create myphp
$docker run -d -p 8080:80 --net=myphp-app -v `pwd`:/var/www/html php-blackfire
结果:
Unable to find image 'php-blackfire:latest' locally
docker: Error response from daemon: pull access denied for php-blackfire, repository does not exist or may require 'docker login'.
See 'docker run --help'.
$ docker login
正在使用现有凭据进行身份验证...登录成功
$ docker run -d -p 8080:80 --net=myphp-app -v \
pwd`:/var/www/html php-blackfire`
Unable to find image 'php-blackfire:latest' locally
docker: Error response from daemon: pull access denied for php-blackfire, repository does not exist or may require 'docker login'.
See 'docker run --help'.
然后我试图找到 Blackfire本地图像:
$docker images | grep black
blackfire/blackfire latest fe5c5468b23d 7 days ago 25.7MB
$ docker run -d -p 8080:80 --net=myphp -v pwd:/var/www/html blackfire/blackfire
26005945907dd55d55d174444dcf53ef176e5b45d0086309496122d0b02e3918
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7768e1266e81 blackfire/blackfire "blackfire-agent" 38 minutes ago Up 38 minutes 8707/tcp blackfire
7.在容器中运行php应用
$docker run -d -p 8080:80 php-docker-apache-example
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6dd287bfbb44 php-docker-apache-example "docker-php-entrypoi…" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp determined_snyder
7768e1266e81 blackfire/blackfire "blackfire-agent" 44 minutes ago Up 44 minutes 8707/tcp blackfire
显示:你好。今天是 10 号星期一。
9. 在 Chrome 中运行分析器
错误:
您是否有权配置此页面?未找到探测,签名无效 (HTTP 200)。故障排除?
docker logs 没有显示相关错误:
$docker logs 6dd287bfbb44 -f
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Mon Dec 10 22:24:13.490536 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.0.32 configured -- resuming normal operations
[Mon Dec 10 22:24:13.490688 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
172.17.0.1 - - [10/Dec/2018:22:25:50 +0000] "GET / HTTP/1.1" 200 407 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"