![]() ![]() Still, if you want to take advantage from the debug mode, it's worth to be set. Setting xdebug.client_host isn't formally required for our profiling purpose. Thus, Xdebug can be started by setting either a specific GET or POST variable, or even an HTTP cookie, we'll see it in action in the next part. We set the xdebug.start_with_request option to trigger in order to run the profiling when a specific trigger is present in the request. In the same way, you should disable the garbage collector (see zend.enable_gc) to get more accurate memory usage data. Pro-tip : if you want to collect very accurate performance metrics, you should consider disabling the "debug" mode as this mode adds overhead at runtime. In order to allow us to test all the features offered by Xdebug, we enable both the debug, develop and profile modes but since we will only use the 'profile' mode in this tutorial, we could have skipped the 'debug' and 'develop' ones. The following lines aim to write the basic configuration into the file docker-php-ext-xdebug.ini. & echo "xdebug.output_dir=/var/To clarify, we first install the Xdebug PHP extension through PECL before enabling it. & echo "xdebug.client_host=" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ & echo "xdebug.start_with_request=trigger" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ & echo "xdebug.mode=debug,develop,profile" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ The installation of Xdebug PHP extension is pretty straightforward and can be achieved by adding this small bunch of lines to the Dockerfile : RUN pecl install xdebug \ If you want to jump directly to the final version of the PHP environment with xdebug ready-to-use, you can take a look at the "xdebug" branch from the GitHub repository. Last but not least, Xdebug provides a profile mode that allows you to - you guessed it - analyze in depth the performance of your code. The develop mode brings more user-friendly var_dump() output and errors. The debug mode allows you to run your code step by step by setting breakpoints. Xdebug provides three modes that can be enabled independently. ![]() If you now query you should get this introduction page : Thanks to the Symfony CLI tool, it can be achieved by running a single command : docker-compose exec -T codeprofiling-php-fpm bash -c "symfony new app -webapp" The next step is about installing a blank Symfony application within the app/ subdirectory. ![]() Now that our docker-compose.yaml and Dockerfile files are set, we can finally build and run our services : docker-compose build -build-arg userid=$(id -g) -build-arg groupid=$(id -u) The initialization of GIT email and username is required by Symfony CLI tool in order to install the framework without any error. The Dockerfile extends the PHP 8.1 basic image to add some extra steps : install basic tools like git and unzip, install Composer and Symfony CLI tools, create a user who will have the same UID and GID than the current host user. & useradd -m -u $userid -g $groupid myuser & mv /root/.symfony/bin/symfony /usr/local/bin/symfony That's all for the docker-compose file for now, let's dive into the Dockerfile for the php-fpm service !ĬOPY -from=composer:latest /usr/bin/composer /usr/bin/composer You will notice in the configuration that Nginx communicates with php-fpm through the port 9000 which is the default port exposed by the php-fpm docker image. Since this file is not very relevant for our profiling concern, we will skip it, but you still can take a look to the one I've set in the GitHub repository. Nginx requires a bit of additional configuration which is brought by the file nf. The Nginx service acts as our web server and allows us to query our PHP application through HTTP on the port 8080. The php-fpm service is built from a custom image defined in a Dockerfile that we will see right after. Here, we define the only two services we need for our profiling purpose. Let's start with the basic docker-compose.yaml configuration file : version: '3.7' We will bootstrap a Symfony application to have something on which perform code profiling. The basic setup is available in this GitHub repository, and you are free to clone it to in order to do your own experiments. For the sake of simplicity, We will rely on docker-compose to achieve this first step - assuming you are already familiar with docker containers. ![]() Tools used for profiling or measuring performance Set up a PHP 8.1 environmentīefore we can use profiling tools, we need to set up a minimalistic PHP environment with a sample application to profile. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |