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

Profiling not enabled when query string parameter MEMPROF_PROFILE is set to dump_on_limit #85

Open
kriptor opened this issue Dec 11, 2022 · 0 comments
Labels

Comments

@kriptor
Copy link

kriptor commented Dec 11, 2022

Description

The following code:

<?php
  echo '<pre>';
  echo '$_GET ';
  print_r($_GET);
  echo 'env MEMPROF_PROFILE value: "' . getenv('MEMPROF_PROFILE') . '"<br>';
  echo 'memprof version: ' . memprof_version() . '<br>';
  echo 'memprof_enabled_flags() ';
  print_r(memprof_enabled_flags());
  echo 'get_loaded_extensions() ';
  print_r(get_loaded_extensions());
  // memprof_dump_callgrind(fopen("/tmp/test.memprof", "w"));
?>

Resulted in this output (when calling /above_script.php?MEMPROF_PROFILE=dump_on_limit):

$_GET Array
(
    [MEMPROF_PROFILE] => dump_on_limit
)
env MEMPROF_PROFILE value: ""
memprof version: 3.0.2
memprof_enabled_flags() Array
(
    [enabled] =>
    [native] => 
    [dump_on_limit] =>
)
get_loaded_extensions() Array
(
    [0] => Core
    [1] => date
    [2] => libxml
    [3] => openssl
    [4] => pcre
    [5] => sqlite3
    [6] => zlib
    [7] => bcmath
    [8] => bz2
    [9] => calendar
    [10] => ctype
    [11] => curl
    [12] => dom
    [13] => hash
    [14] => fileinfo
    [15] => filter
    [16] => ftp
    [17] => gd
    [18] => gettext
    [19] => gmp
    [20] => SPL
    [21] => iconv
    [22] => session
    [23] => intl
    [24] => json
    [25] => ldap
    [26] => mbstring
    [27] => standard
    [28] => mysqlnd
    [29] => pcntl
    [30] => mysqli
    [31] => PDO
    [32] => pdo_mysql
    [33] => pdo_sqlite
    [34] => Phar
    [35] => posix
    [36] => readline
    [37] => Reflection
    [38] => imap
    [39] => SimpleXML
    [40] => soap
    [41] => sockets
    [42] => sodium
    [43] => exif
    [44] => tidy
    [45] => tokenizer
    [46] => xml
    [47] => xmlreader
    [48] => xmlrpc
    [49] => xmlwriter
    [50] => xsl
    [51] => zip
    [52] => cgi-fcgi
    [53] => memprof
    [54] => Zend OPcache
)

But I expected this output instead:

$_GET Array
(
    [MEMPROF_PROFILE] => dump_on_limit
)
env MEMPROF_PROFILE value: ""
memprof version: 3.0.2
memprof_enabled_flags() Array
(
    [enabled] => 1
    [native] => 
    [dump_on_limit] => 1
)
get_loaded_extensions() Array
(
    [0] => Core
    [1] => date
    [2] => libxml
    [3] => openssl
    [4] => pcre
    [5] => sqlite3
    [6] => zlib
    [7] => bcmath
    [8] => bz2
    [9] => calendar
    [10] => ctype
    [11] => curl
    [12] => dom
    [13] => hash
    [14] => fileinfo
    [15] => filter
    [16] => ftp
    [17] => gd
    [18] => gettext
    [19] => gmp
    [20] => SPL
    [21] => iconv
    [22] => session
    [23] => intl
    [24] => json
    [25] => ldap
    [26] => mbstring
    [27] => standard
    [28] => mysqlnd
    [29] => pcntl
    [30] => mysqli
    [31] => PDO
    [32] => pdo_mysql
    [33] => pdo_sqlite
    [34] => Phar
    [35] => posix
    [36] => readline
    [37] => Reflection
    [38] => imap
    [39] => SimpleXML
    [40] => soap
    [41] => sockets
    [42] => sodium
    [43] => exif
    [44] => tidy
    [45] => tokenizer
    [46] => xml
    [47] => xmlreader
    [48] => xmlrpc
    [49] => xmlwriter
    [50] => xsl
    [51] => zip
    [52] => cgi-fcgi
    [53] => memprof
    [54] => Zend OPcache
)

I'm using Docker container based on this Dockerfile: https://github.com/bitnami/containers/blob/459433741bd9d98d8e8eee698db1ee8a21776c86/bitnami/php-fpm/7.4/debian-11/Dockerfile

My actual Docker image uses this Dockerfile where I changed the base one slightly so that I could install the memprof.so:

FROM docker.io/bitnami/minideb:bullseye

ARG TARGETARCH

LABEL org.opencontainers.image.authors="https://bitnami.com/contact" \
      org.opencontainers.image.description="Application packaged by Bitnami" \
      org.opencontainers.image.ref.name="7.4.33-debian-11-r13" \
      org.opencontainers.image.source="https://github.com/bitnami/containers/tree/main/bitnami/php-fpm" \
      org.opencontainers.image.title="php-fpm" \
      org.opencontainers.image.vendor="VMware, Inc." \
      org.opencontainers.image.version="7.4.33"

ENV OS_ARCH="${TARGETARCH:-amd64}" \
    OS_FLAVOUR="debian-11" \
    OS_NAME="linux"

COPY prebuildfs /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Install required system packages and dependencies
RUN install_packages build-essential autoconf git libjudy-dev argon2 ca-certificates curl libargon2-0 libargon2-0-dev libbrotli1 libbsd0 libbz2-1.0 libcom-err2 libcrypt1 libcurl4 libexpat1 libffi7 libfftw3-double3 libfontconfig1 libfreetype6 libgcc-s1 libgcrypt20 libglib2.0-0 libgmp10 libgnutls30 libgomp1 libgpg-error0 libgssapi-krb5-2 libhogweed6 libicu67 libidn2-0 libjpeg62-turbo libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 liblcms2-2 libldap-2.4-2 liblqr-1-0 libltdl7 liblzma5 libmagickcore-6.q16-6 libmagickwand-6.q16-6 libmcrypt4 libmd0 libmemcached11 libnettle8 libnghttp2-14 libonig-dev libonig5 libp11-kit0 libpcre3 libpng16-16 libpq5 libpsl5 libreadline8 librtmp1 libsasl2-2 libsodium23 libsqlite3-0 libsqlite3-dev libssh2-1 libssl-dev libssl1.1 libstdc++6 libsybdb5 libtasn1-6 libtidy5deb1 libtinfo6 libunistring2 libuuid1 libwebp6 libx11-6 libxau6 libxcb1 libxdmcp6 libxext6 libxml2 libxslt1.1 libzip4 procps wget zlib1g
RUN mkdir -p /tmp/bitnami/pkg/cache/ && cd /tmp/bitnami/pkg/cache/ && \
    COMPONENTS=( \
      "php-7.4.33-2-linux-${OS_ARCH}-debian-11" \
    ) && \
    for COMPONENT in "${COMPONENTS[@]}"; do \
      if [ ! -f "${COMPONENT}.tar.gz" ]; then \
        curl -SsLf "https://downloads.bitnami.com/files/stacksmith/${COMPONENT}.tar.gz" -O ; \
        curl -SsLf "https://downloads.bitnami.com/files/stacksmith/${COMPONENT}.tar.gz.sha256" -O ; \
      fi && \
      sha256sum -c "${COMPONENT}.tar.gz.sha256" && \
      tar -zxf "${COMPONENT}.tar.gz" -C /opt/bitnami --strip-components=2 --no-same-owner --wildcards '*/files' && \
      rm -rf "${COMPONENT}".tar.gz{,.sha256} ; \
    done
RUN apt-get update && apt-get upgrade -y && \
    apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives
RUN sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS    90/' /etc/login.defs && \
    sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS    0/' /etc/login.defs && \
    sed -i 's/sha512/sha512 minlen=8/' /etc/pam.d/common-password

ENV APP_VERSION="7.4.33" \
    BITNAMI_APP_NAME="php-fpm" \
    PATH="/opt/bitnami/php/bin:/opt/bitnami/php/sbin:$PATH"

RUN git clone --depth 1 --branch 3.0.2 https://github.com/arnaud-lb/php-memory-profiler.git /tmp/php-memory-profiler && \
    cd /tmp/php-memory-profiler && \
    ls -la &&  \
    phpize && \
    ./configure && \
    make && \
    make install && \
    rm -rf /tmp/php-memory-profiler

EXPOSE 9000

WORKDIR /app
CMD [ "php-fpm", "-F", "--pid", "/opt/bitnami/php/tmp/php-fpm.pid", "-y", "/opt/bitnami/php/etc/php-fpm.conf" ]

If I set the env var MEMPROF_PROFILE=dump_on_limit then profiler is enabled for every request, which slows down the whole site of course and which I'm trying to avoid.

What I'm hopping to achieve is heaving profiler do its job only if request variable is set and sit idly otherwise. As I understood the documentation this should be achievable but maybe I just didn't understand it correctly. :)

php-memprof Version

3.0.2

PHP Version

7.4.33

Operating System

Debian 11

@kriptor kriptor added the bug label Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant