Skip to content

Commit e6661e8

Browse files
authored
fix: updates cloud run mc php nginx sample (GoogleCloudPlatform#1913)
1 parent c4da994 commit e6661e8

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

run/multi-container/hello-php-nginx-sample/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ gcloud builds submit --tag=${REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/p
5151

5252
4. Configure the service with the appropriate memory limit.
5353

54-
You will see as you read through `service.yaml`, that the memory limit has been explicitly
55-
set to `320Mi` due to container concurrency of `1` with a single `fpm` worker.
54+
You will see as you read through `service.yaml`, that the memory limit has been explicitly set to `335M`. This leaves ~143M for PHP processes after allocating 192M for opcache.
5655
See how we got [here](https://cloud.google.com/run/docs/configuring/services/memory-limits#optimizing) and read more about how to [optimize for concurrency](https://cloud.google.com/run/docs/tips/general#optimize_concurrency).
5756

57+
**Note:** This sample does not contain extra configuration to tune php-fpm settings to specify the number of workers to correlate with the container concurrency.
58+
5859
5. Deploy the multi-container service.
5960

6061
From within `service.yaml`, customize the `service.yaml` file with your own project values by replacing

run/multi-container/hello-php-nginx-sample/php-app/Dockerfile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@
2222

2323
FROM php:8-fpm-alpine
2424

25-
# Use the default production configuration
26-
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
27-
28-
RUN docker-php-ext-install opcache
29-
30-
# COPY php.ini /usr/local/etc/php
31-
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini
25+
# Configure PHP for Cloud Run.
26+
# Precompile PHP code with opcache.
27+
RUN docker-php-ext-install -j "$(nproc)" opcache
28+
RUN set -ex; \
29+
{ \
30+
echo "; Cloud Run enforces memory & timeouts"; \
31+
echo "memory_limit = -1"; \
32+
echo "; Configure Opcache for Containers"; \
33+
echo "opcache.enable = 1"; \
34+
echo "opcache.validate_timestamps = 0"; \
35+
echo "opcache.memory_consumption = 192"; \
36+
echo "opcache.max_accelerated_files = 10000"; \
37+
echo "opcache.max_wasted_percentage = 10"; \
38+
echo "opcache.interned_strings_buffer = 16";\
39+
} > "$PHP_INI_DIR/conf.d/cloud-run.ini"
3240

3341
COPY . /var/www/html/
3442

43+
# Use the default production configuration
44+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
45+
3546
# [END cloudrun_hello_mc_nginx_app_dockerfile]

run/multi-container/hello-php-nginx-sample/php-app/opcache.ini

Lines changed: 0 additions & 11 deletions
This file was deleted.

run/multi-container/hello-php-nginx-sample/service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
resources:
4444
limits:
4545
cpu: 500m
46-
memory: 256Mi
46+
memory: 256M
4747
- name: hellophp
4848
image: "REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME/php"
4949
env:
@@ -55,5 +55,5 @@ spec:
5555
# Explore more how to set memory limits in Cloud Run
5656
# https://cloud.google.com/run/docs/tips/general#optimize_concurrency
5757
# https://cloud.google.com/run/docs/configuring/services/memory-limits#optimizing
58-
memory: 320Mi
58+
memory: 335M
5959
# [END cloudrun_mc_hello_php_nginx_mc]

0 commit comments

Comments
 (0)