Skip to content

Instantly share code, notes, and snippets.

@spyzhov
Created September 18, 2019 09:37
Show Gist options
  • Save spyzhov/1fb0e156049adba4962254d39b5926d9 to your computer and use it in GitHub Desktop.
Save spyzhov/1fb0e156049adba4962254d39b5926d9 to your computer and use it in GitHub Desktop.

HOWTO: Install XHProf

1. Add php extension

Go to the Dockerfile.dev and add lines:

# Install XHProf
RUN cd /root && \
    curl "https://github.com/tideways/php-xhprof-extension/archive/v5.0.0.tar.gz" -fsL -o ./a.tar.gz  && \
    tar xf ./a.tar.gz && \
    cd ./php-xhprof-extension-5.0.0 && \
    phpize && \
    ./configure && \
    make && \
    make install && \
    cd .. && rm -rf ./a.tar.gz ./php-xhprof-extension-5.0.0 && \
    docker-php-ext-enable tideways_xhprof && \
    cd /srv/www/service/

2. Add trace in php

Go to the public/index.php and add lines:

<?php

// after use (...) block:

// xhprof: init
tideways_xhprof_enable();

// ... all requires and calls goes there...

// xhprof: save data
$run = uniqid();
$type = "service-name";
$filename = "/srv/www/service/var/profiles/$run.$type.xhprof";
file_put_contents($filename, serialize(tideways_xhprof_disable()));

3. Add UI for XHProf

Go to the docker-compose.yml and add lines:

services:
    # ...
    xhprof:
        image: tuimedia/xhprof-docker:0.9.4
        volumes:
            - ./var/profiles:/profiles
        ports:
            - "8081:80"
    # ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment