Skip to content

Instantly share code, notes, and snippets.

@rezigned
Last active December 12, 2015 07:58
Show Gist options
  • Save rezigned/4740479 to your computer and use it in GitHub Desktop.
Save rezigned/4740479 to your computer and use it in GitHub Desktop.
Installation & Setup

How to install Sphinx Doc and Create a new Project on OSX

Prerequisites

  • Xcode Command Line tools

Steps

# You might need to execute this command with 'root' previllage
easy_install -U Sphinx

Create a new project

  • Create a new empty directory e.g. mkdir ~/docs/project
  • Go to newly created directory and run sphinx-quickstart and follow the instructions on screen.
  • To compile your project. Run make html

How to install XHProf on Mac OS X

First of all download the latest version of xhprof with pecl

# d flag tells pecl to just download the file
sudo pecl d xhprof-0.9.2

# extract the file
tar -xzf xhprof-0.9.2.tgz

cd xhprof-0.9.2/extension/

Make sure to compile it using 64bit architecture

MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"

export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
sudo phpize
> Configuring for:
> PHP Api Version:         20090626
> Zend Module Api No:      20090626
> Zend Extension Api No:   220090626

# compile
./configure
make
sudo make install
> Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/

How to install XHProf on Ubuntu

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar xvf xhprof-0.9.2.tgz
cd ./xhprof-0.9.2/extension/
phpize
./configure --with-php-config=/usr/local/bin/php-config
make
make install
make test

Enable xhprof by adding the following value to php.ini

[xhprof]
extension=xhprof.so
; Directory where xhprof saves the result
; xhprof.output_dir=/var/tmp

Check to see if xhprof is enabled

php -i | grep xhprof
> xhprof => 0.9.2

Usage

Before we can start profiling our application, we need to create 2 files

header.php

if (extension_loaded('xhprof')) {
    include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_lib.php';
    include_once '/usr/local/lib/php/xhprof_lib/utils/xhprof_runs.php';
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}

footer.php

if (extension_loaded('xhprof')) {
    $namespace   = 'myapp';  // namespace for your application
    $xhprof_data = xhprof_disable();
    $xhprof_runs = new XHProfRuns_Default();
    $run_id      = $xhprof_runs->save_run($xhprof_data, $namespace);
 
    // url to the XHProf UI libraries (change the host name and path)
    $profiler_url = sprintf('http://localhost/xhprof/xhprof_html/index.php?run=%s&source=%s', $run_id, $namespace);
    echo '<a href="'. $profiler_url .'" target="_blank">Profiler output</a>';
}

Then we have to add the following code to .htaccess file (or include those files in your php application manually)

php_value auto_prepend_file /path/to/header.php
php_value auto_append_file /path/to/footer.php
References
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment