Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use async php runtime #823

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#764](https://github.com/open-telemetry/opentelemetry-demo/pull/764))
* [chore] align memory limits with Helm chart
([#781](https://github.com/open-telemetry/opentelemetry-demo/pull/781))
* Use an async PHP runtime, bump versions to latest betas
([#823](https://github.com/open-telemetry/opentelemetry-demo/pull/823))
11 changes: 4 additions & 7 deletions src/quoteservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,21 @@ RUN composer install \
--no-dev \
--prefer-dist

FROM php:8.2-apache
FROM php:8.2-cli

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
&& install-php-extensions \
opcache \
pcntl \
protobuf \
open-telemetry/opentelemetry-php-instrumentation@1.0.0beta2
opentelemetry-1.0.0beta3

WORKDIR /var/www
COPY --from=build /tmp/vendor/ ./vendor/
COPY ./src/quoteservice/ /var/www

ENV APACHE_DOCUMENT_ROOT /var/www/public
RUN sed -ri -e 's|/var/www/html|${APACHE_DOCUMENT_ROOT}|g' /etc/apache2/sites-available/*.conf \
&& a2enmod rewrite \
&& echo "ServerName quoteservice" >> /etc/apache2/apache2.conf \
&& sed -i "s/80/\$\{QUOTE_SERVICE_PORT\}/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
CMD php public/index.php

USER www-data
EXPOSE ${QUOTE_SERVICE_PORT}
3 changes: 1 addition & 2 deletions src/quoteservice/app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ function calculateQuote($jsonObject): float
$span = Span::getCurrent();
$span->addEvent('Received get quote request, processing it');

$body = $request->getBody()->getContents();
$jsonObject = json_decode($body, true);
$jsonObject = $request->getParsedBody();

$data = calculateQuote($jsonObject);

Expand Down
11 changes: 6 additions & 5 deletions src/quoteservice/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"require": {
"php": ">= 8.2",
"ext-json": "*",
"monolog/monolog": "2.8.0",
"open-telemetry/api": "1.0.0beta4",
"open-telemetry/sdk": "1.0.0beta3",
"open-telemetry/exporter-otlp": "1.0.0beta3",
"open-telemetry/opentelemetry-auto-slim": "1.0.0beta4",
"monolog/monolog": "3.3.1",
"open-telemetry/api": "1.0.0beta5",
"open-telemetry/sdk": "1.0.0beta6",
"open-telemetry/exporter-otlp": "1.0.0beta5",
"open-telemetry/opentelemetry-auto-slim": "1.0.0beta7",
"guzzlehttp/guzzle": "7.4.5",
"php-di/php-di": "6.4.0",
"php-di/slim-bridge": "3.2.0",
"php-http/guzzle7-adapter": "1.0.0",
"react/http": "v1.8.0",
"slim/psr7": "1.5",
"slim/slim": "4.10.0"
},
Expand Down
18 changes: 0 additions & 18 deletions src/quoteservice/public/.htaccess

This file was deleted.

28 changes: 26 additions & 2 deletions src/quoteservice/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use OpenTelemetry\API\Common\Log\LoggerHolder;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LogLevel;
use React\EventLoop\Loop;
use React\Http\HttpServer;
use React\Socket\SocketServer;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';
Expand Down Expand Up @@ -59,6 +63,26 @@

// Add Error Middleware
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
Loop::get()->addSignal(SIGTERM, function() {
exit;
});

// Run App
$app->run();
$server = new HttpServer(function (ServerRequestInterface $request) use ($app) {
$response = $app->handle($request);
echo sprintf('[%s] "%s %s HTTP/%s" %d %d %s',
date('Y-m-d H:i:sP'),
$request->getMethod(),
$request->getUri()->getPath(),
$request->getProtocolVersion(),
$response->getStatusCode(),
$response->getBody()->getSize(),
PHP_EOL,
);

return $response;
});
$address = '0.0.0.0:' . getenv('QUOTE_SERVICE_PORT');
$socket = new SocketServer($address);
$server->listen($socket);

echo "Listening on: {$address}" . PHP_EOL;