Skip to content

Commit

Permalink
Add FFI Fiber support preload example (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevay authored Dec 25, 2021
1 parent 191d4bc commit 2038e99
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[docker-compose.*.yaml]
indent_size = 2

[Makefile]
indent_style = tab
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ collector:
docker-compose -f docker-compose-collector.yaml run -e OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317 --rm php php ./examples/AlwaysOnOTLPGrpcExample2.php
docker-compose -f docker-compose-collector.yaml stop

fiber-ffi-example:
@docker-compose -f docker-compose.fiber-ffi.yaml -p opentelemetry-php_fiber-ffi-example up -d web
metrics-prometheus-example:
@docker-compose -f docker-compose.prometheus.yaml up -d web
@docker-compose -f docker-compose.prometheus.yaml run php-prometheus php /var/www/public/examples/prometheus/PrometheusMetricsExample.php
@docker-compose -f docker-compose.prometheus.yaml -p opentelemetry-php_metrics-prometheus-example up -d web
@docker-compose -f docker-compose.prometheus.yaml -p opentelemetry-php_metrics-prometheus-example run --rm php php examples/prometheus/PrometheusMetricsExample.php
stop-prometheus:
@docker-compose -f docker-compose.prometheus.yaml stop
@docker-compose -f docker-compose.prometheus.yaml -p opentelemetry-php_metrics-prometheus-example stop
proto:
@docker-compose -f docker-compose.proto.yaml up proto
bash:
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.fiber-ffi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'
services:
web:
image: nginx:alpine
ports:
- '8080:80'
depends_on:
- php
volumes:
- ./docker/examples/nginx.conf:/etc/nginx/conf.d/default.conf:ro
php:
build:
context: .
dockerfile: docker/examples/Dockerfile
args:
- PHP_VERSION=8.1-fpm
- EXT_ENABLE=ffi
environment:
- OTEL_PHP_FIBERS_ENABLED=true
command:
- php-fpm
- -d
- opcache.preload=/php/vendor/autoload.php
volumes:
- ./tests/Context/Fiber/test_context_switching_ffi_observer.phpt:/var/www/public/index.php
- ./:/php
17 changes: 10 additions & 7 deletions docker-compose.prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ services:
ports:
- 8080:80
depends_on:
- php-prometheus
- php
volumes:
- ./docker/prometheus/nginx.conf:/etc/nginx/conf.d/default.conf
- ./docker/prometheus/index.php:/var/www/public/index.php
php-prometheus:
- ./docker/examples/nginx.conf:/etc/nginx/conf.d/default.conf:ro
php:
build:
context: .
dockerfile: docker/prometheus/Dockerfile
dockerfile: docker/examples/Dockerfile
args:
- PHP_VERSION=7.4-fpm
- EXT_ENABLE=redis
volumes:
- ./:/var/www/public
- ./examples/prometheus/index.php:/var/www/public/index.php
- ./:/php
depends_on:
- redis
- prometheus
- prometheus
34 changes: 34 additions & 0 deletions docker/examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

ARG PHP_VERSION
ARG PHP_ALPINE_VERSION

FROM php:${PHP_VERSION:+${PHP_VERSION}-}alpine${PHP_ALPINE_VERSION} AS php

ENV PROJECT_ROOT=/php

RUN set -eux; \
apk add --no-cache \
bash \
; \
adduser -u 1000 -DSh /php php php

ARG EXT_INSTALL
ARG EXT_ENABLE=''
RUN --mount=from=mlocati/php-extension-installer,dst=/build/extension-installer,src=/usr/bin/install-php-extensions \
set -eux; \
/build/extension-installer \
opcache \
${EXT_INSTALL:-${EXT_ENABLE}} \
; \
docker-php-ext-enable \
opcache \
${EXT_ENABLE} \
;

RUN set eux; \
mkdir -p /usr/local/lib/php/vendor; \
echo "<?php file_exists('/php/vendor/autoload.php') and require '/php/vendor/autoload.php';" > /usr/local/lib/php/vendor/autoload.php; \
echo 'auto_prepend_file=vendor/autoload.php' > "$PHP_INI_DIR/conf.d/99-autoload.ini"

USER php
WORKDIR /php
12 changes: 12 additions & 0 deletions docker/examples/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 80;
server_name _;
root /var/www/public;

location / {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
11 changes: 0 additions & 11 deletions docker/prometheus/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions docker/prometheus/nginx.conf

This file was deleted.

2 changes: 0 additions & 2 deletions examples/prometheus/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

declare(strict_types=1);

require __DIR__ . '/../../vendor/autoload.php';

\Prometheus\Storage\Redis::setDefaultOptions(
[
'host' => 'redis',
Expand Down

0 comments on commit 2038e99

Please sign in to comment.