diff --git a/Dockerfile b/Dockerfile index 327d1a1e1..d545f1d84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,9 @@ ENV LANG="en_US.UTF-8" \ MYSQL_DATABASE="azuracast" \ PREFER_RELEASE_BUILDS="false" \ COMPOSER_PLUGIN_MODE="false" \ - ADDITIONAL_MEDIA_SYNC_WORKER_COUNT=0 + ADDITIONAL_MEDIA_SYNC_WORKER_COUNT=0 \ + PROFILING_EXTENSION_ENABLED=0 \ + PROFILING_EXTENSION_ALWAYS_ON=0 # Entrypoint and default command ENTRYPOINT ["/usr/local/bin/uptime_wait"] diff --git a/azuracast.dev.env b/azuracast.dev.env index 2b1e8a14e..26231dce4 100644 --- a/azuracast.dev.env +++ b/azuracast.dev.env @@ -63,3 +63,21 @@ MYSQL_SLOW_QUERY_LOG=1 # if you are seeing the `Too many connections` error in the logs. # Default: 100 MYSQL_MAX_CONNECTIONS=100 + +# Enable the profiling extension. +# Profiling data can be viewed by visiting http://your-azuracast-site/?SPX_KEY=dev&SPX_UI_URI=/ +# Default: 0 +PROFILING_EXTENSION_ENABLED=1 + +# Profile ALL requests made to this account. +# This will have significant performance impact on your installation and should only be used in test circumstances. +# Default: 0 +PROFILING_EXTENSION_ALWAYS_ON=0 + +# Configure the value for the SPX_KEY parameter needed to access the profiling dashboard +# Default: dev +PROFILING_EXTENSION_HTTP_KEY=dev + +# Configure the IP whitelist for the profiling dashboard +# Default: * +PROFILING_EXTENSION_HTTP_IP_WHITELIST=* diff --git a/azuracast.sample.env b/azuracast.sample.env index 9e8cd4325..a7bcffd45 100644 --- a/azuracast.sample.env +++ b/azuracast.sample.env @@ -128,3 +128,31 @@ MYSQL_MAX_CONNECTIONS=100 # by creating additional worker processes to consume messages # Default: 0 # ADDITIONAL_MEDIA_SYNC_WORKER_COUNT=0 + +# +# PHP-SPX profiling extension Configuration +# +# These environment variables allow you to enable and configure the PHP-SPX profiling extension +# which can be helpful when debugging resource issues in AzuraCast. +# +# The profiling dashboard can be accessed by visting https://yourdomain.com/?SPX_KEY=dev&SPX_UI_URI=/ +# If you change the PROFILING_EXTENSION_HTTP_KEY variable change the value for SPX_KEY accordingly. +# + +# Enable the profiling extension. +# Profiling data can be viewed by visiting http://your-azuracast-site/?SPX_KEY=dev&SPX_UI_URI=/ +# Default: 0 +PROFILING_EXTENSION_ENABLED=1 + +# Profile ALL requests made to this account. +# This will have significant performance impact on your installation and should only be used in test circumstances. +# Default: 0 +PROFILING_EXTENSION_ALWAYS_ON=0 + +# Configure the value for the SPX_KEY parameter needed to access the profiling dashboard +# Default: dev +# PROFILING_EXTENSION_HTTP_KEY=dev + +# Configure the IP whitelist for the profiling dashboard +# Default: * +# PROFILING_EXTENSION_HTTP_IP_WHITELIST=* diff --git a/docker-compose.testing.yml b/docker-compose.testing.yml index 8a8937b22..89b7672de 100644 --- a/docker-compose.testing.yml +++ b/docker-compose.testing.yml @@ -2,12 +2,7 @@ version : '2.2' services : web : - image : azuracast_cli:latest environment : APPLICATION_ENV : 'testing' - build : - context : ./util/docker/testing - cache_from : - - azuracast/azuracast_web_v2:latest volumes : - .:/var/azuracast/www diff --git a/util/docker/testing/Dockerfile b/util/docker/testing/Dockerfile deleted file mode 100644 index 41f34c4cc..000000000 --- a/util/docker/testing/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM azuracast/azuracast_web_v2:latest - -RUN apt-get update \ - && apt-get install -q -y php7.4-xdebug - -ENV PATH="${PATH}:/var/azuracast/.composer/vendor/bin" \ - APPLICATION_ENV="testing" - -USER root diff --git a/util/docker/web/php/php.ini.tmpl b/util/docker/web/php/php.ini.tmpl index cf1336903..292e8dff3 100644 --- a/util/docker/web/php/php.ini.tmpl +++ b/util/docker/web/php/php.ini.tmpl @@ -12,4 +12,16 @@ opcache.enable_cli=1 {{if eq .Env.APPLICATION_ENV "production"}} opcache.revalidate_freq={{ default .Env.PHP_OPCACHE_REVALIDATE_FREQUENCY "60" }} -{{end}} \ No newline at end of file +{{end}} + +{{if eq .Env.PROFILING_EXTENSION_ENABLED "1"}} +spx.http_enabled=1 +spx.data_dir=/var/azuracast/www_tmp +spx.http_key={{ default .Env.PROFILING_EXTENSION_HTTP_KEY "dev" }} +spx.http_ip_whitelist={{ default .Env.PROFILING_EXTENSION_HTTP_IP_WHITELIST "*" }} +zlib.output_compression=0 + +{{if eq .Env.PROFILING_EXTENSION_ALWAYS_ON "1"}} +spx.http_profiling_enabled=1 +{{end}} +{{end}} diff --git a/util/docker/web/php/www.conf.tmpl b/util/docker/web/php/www.conf.tmpl index 78d2eaf3a..0ba470797 100644 --- a/util/docker/web/php/www.conf.tmpl +++ b/util/docker/web/php/www.conf.tmpl @@ -21,4 +21,8 @@ chdir = / clear_env=No catch_workers_output = yes -decorate_workers_output = no \ No newline at end of file +decorate_workers_output = no + +{{if eq .Env.PROFILING_EXTENSION_ENABLED "1"}} +process.dumpable = yes +{{end}} diff --git a/util/docker/web/setup/php.sh b/util/docker/web/setup/php.sh index 5083863e7..664ae2423 100644 --- a/util/docker/web/setup/php.sh +++ b/util/docker/web/setup/php.sh @@ -9,7 +9,7 @@ apt-get update $minimal_apt_get_install php7.4-fpm php7.4-cli php7.4-gd \ php7.4-curl php7.4-xml php7.4-zip php7.4-bcmath php7.4-gmp \ php7.4-mysqlnd php7.4-mbstring php7.4-intl php7.4-redis \ - php7.4-maxminddb \ + php7.4-maxminddb php7.4-xdebug \ mariadb-client # Copy PHP configuration @@ -21,3 +21,19 @@ cp /bd_build/php/www.conf.tmpl /etc/php/7.4/fpm/www.conf.tmpl # Install Composer curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer + +# Install PHP SPX profiler +$minimal_apt_get_install php7.4-dev zlib1g-dev build-essential + +cd /bd_build +git clone https://github.com/NoiseByNorthwest/php-spx.git +cd php-spx +phpize +./configure +make +sudo make install + +apt-get remove --purge -y php7.4-dev zlib1g-dev build-essential + +echo "extension=spx.so" > /etc/php/7.4/cli/conf.d/30-spx.ini +echo "extension=spx.so" > /etc/php/7.4/fpm/conf.d/30-spx.ini