Skip to content

Instantly share code, notes, and snippets.

@ramsey
Last active May 31, 2018 20:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramsey/5eaff1bb420506f7aef5eef533a413c9 to your computer and use it in GitHub Desktop.
Save ramsey/5eaff1bb420506f7aef5eef533a413c9 to your computer and use it in GitHub Desktop.

Running Xhgui With Tideways Through a Docker Container

Run Xhgui Docker Container

cd ~
git clone https://github.com/perftools/xhgui.git
docker run --name xhgui -d -p 8880:80 -P -v "$HOME/xhgui":/var/www/xhgui clarencep/xhgui
docker exec xhgui bash -c 'cd /var/www/xhgui && \
    curl --silent https://raw.githubusercontent.com/composer/getcomposer.org/master/web/installer | php -- --quiet && \
    php composer.phar install'
open http://localhost:8880/

Install Tideways Extension in the Container

docker exec xhgui bash -c 'cd ~ && \
    yum -q install -y make automake gcc gcc-c++ kernel-devel php71w-devel && \
    curl -sLo tideways.tar.gz https://github.com/tideways/php-profiler-extension/archive/master.tar.gz && \
    mkdir -p tideways && \
    tar zxf tideways.tar.gz -C tideways --strip-components=1 && \
    cd tideways && \
    phpize && \
    ./configure && \
    make && \
    make install && \
    echo -e "extension=tideways.so\ntideways.auto_prepend_library=0" >> /etc/php.d/tideways.ini && \
    echo "Done!"'

Configure Xhgui to Profile Every Request

docker exec xhgui bash -c "sed -i '/rand(1, 100)/ s|^|// |' /var/www/xhgui/config/config.default.php && \
    sed -i '/rand(1, 100)/a return true;' /var/www/xhgui/config/config.default.php"

Profile a CLI Script Using the Docker Container

# Copy files from a directory (in this case, the current one) into the running container
docker cp . xhgui:/code

# Run the script you want to profile in the container,
# prepending it with the Xhgui header
docker exec xhgui php -d auto_prepend_file=/var/www/xhgui/external/header.php /code/my_script.php

# Open Xhgui and enjoy!
open http://localhost:8880/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment