Coder Social home page Coder Social logo

stefanfisk / docker-xhgui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edyan/docker-xhgui

0.0 2.0 0.0 46 KB

An xhgui (with nginx, mongodb and php) container for profiling PHP Applications.

Home Page: https://hub.docker.com/r/edyan/xhgui/

License: Apache License 2.0

Shell 27.33% Dockerfile 60.28% PHP 12.39%

docker-xhgui's Introduction

Xhgui docker image

Build Status Docker Pulls

Docker Hub: https://hub.docker.com/r/edyan/xhgui

Docker containers that runs xhgui (which needs mongodb and PHP).

It's based on :

It's made for development purposes. You need to find the right version for your project. Use 5.6 for PHP 5.6 projects and 7.2 for PHP 7.x projects. Just make sure you have the mongodb extension enabled (v1.5) on your main PHP container.

To use it in an integrated environment, try Stakkr

Example

To make it work, you need to link it to an existing PHP environment. Example via docker-compose.yml :

version: '2'
services:
  xhgui:
    image: edyan/xhgui:php7.2
    # I need to access xhgui
    ports:
      - "9000:80"
    volumes:
      - ./xhgui-config.php:/usr/local/src/xhgui/config/config.php
  php:
    hostname: php
    command: /usr/bin/php -S 0.0.0.0:80 -t /var/www
    image: edyan/php:7.2 # That image contains mongodb extension from PECL
    # To have the new mounted volumes as well as the default volumes of xhgui (its source code)
    volumes_from: [xhgui]
    ports:
      - "8000:80"
    volumes:
      - ./src:/var/www

As seen above, you need to mount your own configuration file that connects to the right mongodb server. The xhgui-config.php file, in our case (see the official xhgui repo), will contain (note the db.host):

<?php
return array(
    'debug' => false,
    'mode' => 'development',
    'save.handler' => 'mongodb',
    'db.host' => 'mongodb://xhgui',
    'db.db' => 'xhprof',
    'db.options' => array(),
    'templates.path' => dirname(__DIR__) . '/src/templates',
    'date.format' => 'M jS H:i:s',
    'detail.count' => 6,
    'page.limit' => 25,
    'profiler.enable' => function () {
        return true;
    },
    'profiler.simple_url' => function ($url) {
        return preg_replace('/\=\d+/', '', $url);
    }
);

And the src/index.php:

<?php

require_once('/usr/local/src/xhgui/external/header.php');

function test_xhgui()
{
    $data = [];
    for ($i = 0; $i < 5000; $i++) {
        $data[] = $i * $i;
        sort($data);
    }
}

test_xhgui();

Finally, launch the environment with : docker-compose up --force-recreate. Then call http://localhost:8000/index.php in your browser and get reports from http://localhost:9000.

Call the profiler

With require_once

You have two ways to call the profiler. The first one, the most easiest, is to require the file from your script. For that you must mount the volumes (with volumes_from) of the xhgui container to your php container. The code is the following:

<?php

require_once('/usr/local/src/xhgui/external/header.php');
// ... Code below

Globally

If you want to profile everything then you must override the second one, by altering the php.ini configuration and use PHP's auto_prepend_file directive:

auto_prepend_file=/usr/local/src/xhgui/external/header.php

If you use edyan/php you can override the configuration. See the documentation

Environment variables

  • XHGUI_MONGO_HOST default to mongodb://127.0.0.1, used in XHGui config file.
  • MONGO_PORT default to 27017
  • PHP_WEBSERVER_PORT default to 80

Quick Test

A docker-compose file is available to do some tests:

$ docker-compose -f docker-compose.sample.yml up --force-recreate -d 
# Enter the php container
$ docker-compose -f docker-compose.sample.yml exec php bash
# Create a file
$ mkdir -p /var/www
# As we didn't mount the configuration file, we force the env variable for the server
$ echo '<?php putenv("XHGUI_MONGO_HOST=mongodb://xhgui"); require_once("/usr/local/src/xhgui/external/header.php"); $a=[]; for($i=0; $i<10000; $i++){ $a[]=$i; } sort($a); echo "Done";' > /var/www/index.php

Now open http://localhost:8000/index.php to read the new file created. Then http://localhost:9000 to see the report.

Clean :

$ docker-compose -f docker-compose.sample.yml down 

docker-xhgui's People

Contributors

edyan avatar jmartin82 avatar ngyuki avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.