PHPackages                             kehikko/profiler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. kehikko/profiler

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

kehikko/profiler
================

Profiling for kehikko framework

1.0.2(7y ago)08MITPHPPHP &gt;=7.0.0

Since Dec 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kehikko/profiler)[ Packagist](https://packagist.org/packages/kehikko/profiler)[ RSS](/packages/kehikko-profiler/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Profiling PHP
=============

[](#profiling-php)

[![Header](screenshots/header.png)](screenshots/header.png)

Generic profiling implementation for PHP.

Has a browser based UI to view profiled calls.

Tested with *tideways* and *PHP 7.2* in *Ubuntu 18.04*.

All the code is based on a much older implementation that used *xhprof* and *PHP 5.x* (tested and used at least in *Ubuntu 14.04* and *CentOS/cPanel v???*). Ported the code as a standalone version from *Kehikko v1* framework when starting *Kehikko v2*.

Should still work even with *PHP 5.x* since no changes have been made to the core functionality, but I made *PHP 7.0*as a requirement when installing this from *Composer*.

Requirements
------------

[](#requirements)

***PHP 7.0***, PHP ***profiler extension*** (listed below) and command ***dot*** (from GraphViz). ***Twig*** is optional since it can be installed using *Composer*.

One of these PHP-extensions is required:

- tideways
- uprofiler
- xhprof

In *Ubuntu 18.04* you should be able to install required depencies this way:

```
apt install php-tideways graphviz
phpenmod tideways
```

Simple test example
-------------------

[](#simple-test-example)

Do the following after you have installed tideways and graphviz:

```
git clone https://github.com/kehikko/profiler.git
cd profiler
composer install
php example/example.php
php -S localhost:8080 web/index.php
```

And if you did this on your local machine, you should be able to browse to url `http://localhost:8080`and see some results.

Install
-------

[](#install)

To install this profiler into existing project, run:

```
composer require kehikko/profiler
```

If you plan to use this without *Composer*, you need to install *Twig* manually so that it is autoloaded when this profiler code is run.

The part that writes profiling data doe not need *Twig*. Only the part that is used to view profiled calls, needs *Twig*.

**NOTE:** Usually you probably do not want to install profiler into your project and it should be installed elsewhere in a manner like in *Simple test example* and `profiler.php` included to your project from there only on local test installation.

Setup
-----

[](#setup)

### Generating profiling data

[](#generating-profiling-data)

Call `profiler_start` from your code:

```
/* optional profiler.php include, done automatically when using composer autoloader */
//require_once '/profiler/install/dir/profiler.php';

/* do this somewhere in your startup code,
 * path to profiler data directory is optional, default shown here
 */
profiler_start('/tmp/kehikko-php-profiler');
```

Call `profiler_stop` later (or don't and let it be called automatically when PHP execution stops):

```
profiler_stop();
```

Also you can call `profiler_running` to see whether or not profiler has been started:

```
if (profiler_running() && environment_is_in_production()) {
    error_log('running profiler in production environment, stop now!');
    die;
}
```

### Apache

[](#apache)

Enable *mod\_rewrite* in Apache and add/set this to your `.htaccess` in your public web directory:

```
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^_profiler(/.*)?$ profiler.php [NC,L,NE]

```

Create a PHP file called `profiler.php` in that same directory with following contents:

```
