Skip to content

Instantly share code, notes, and snippets.

@rija
Last active October 18, 2021 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rija/849f73ae17b0b25196c4a94019cde2d2 to your computer and use it in GitHub Desktop.
Save rija/849f73ae17b0b25196c4a94019cde2d2 to your computer and use it in GitHub Desktop.
Configuring xhprof and xhgui for a multi-containers setup (nginx/php-fpm)

tutorial

Source:

https://www.digitalocean.com/community/tutorials/how-to-set-up-xhprof-and-xhgui-for-profiling-php-applications-on-ubuntu-14-04

The steps for installing mongodb server, the PECL mongodb PHP extension (which is called mongodb, not the legacy mongo), xhprof need to be peformed on the docker container runnning php-fpm.

The steps for configuring the web server for xhgui are to be performed on the container running the web server.

Both containers (nginx and php-fpm) need to share the server root /var/www in which the web app and the xgui app needs to be located.

Note: This only work for PHP 5+. For PHP 7+ replace the xhprof PHP extension with tideways_xhprof PHP extension.

errors and resolution

Problem 1 - alcaeus/mongo-php-adapter 1.0.0 requires mongodb/mongodb ^1.0.1 -> satisfiable by mongodb/mongodb[1.0.1, 1.0.2].

resolution:

https://www.digitalocean.com/community/tutorials/how-to-set-up-xhprof-and-xhgui-for-profiling-php-applications-on-ubuntu-14-04?comment=47379

Server at localhost:27017 reports wire version 0, but this version of libmongoc requires at least 3 (MongoDB 3.0): generic server error

resolution:

https://unix.stackexchange.com/questions/272140/how-to-install-mongodb-3-x-in-debian-jessie-8-mongodb-web-only-supports-whee#321603

WARNING: [pool www] child 5 said into stderr: "NOTICE: PHP message: xhgui - invalid document for insert: keys cannot contain ".": "main()==>load::webroot/index.php""

resolution :

perftools/xhgui#209 (comment)

404 Error on /run/view?id=5b33e6e29825e900064b6a66

Resolution: perftools/xhgui#196

configuration for xhgui nginx virtualhost:

server {
    listen   80;
    server_name xhgui.example.com;
    root   /var/www/xhgui/webroot/;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass php-upstream;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    }
}

enabling profiling in the web app

in your web-app's Nginx virtualhost config, add:

fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/xhgui/external/header.php";

Example:

server {

...

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/xhgui/external/header.php";
        include fastcgi_params;
    }
 ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment