GithubHelp home page GithubHelp logo

humweb / laravel-xhprof Goto Github PK

View Code? Open in Web Editor NEW

This project forked from laracraft-tech/laravel-xhprof

0.0 0.0 0.0 43 KB

Easy XHProf setup to profile your laravel application!

License: MIT License

PHP 100.00%

laravel-xhprof's Introduction

Logo Laravel XHProf

Latest Stable Version License

Introduction

Laravel XHProf provides you with a simple setup to profile your laravel application with the well known XHProf PHP extension originally developed by facebook. It also leads you through the steps to install XHProf UI, a UI to visualize, save and analyze the results of the profiling.

Installation

First you'll need to install the PHP extension. It's highly recommended using ondrejs ppa. It's well maintained and provides quite all PHP versions.

Normal environment

If you have a normal PHP environment, just install the XHProf extension:

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install php php-xhprof graphviz
$ # you can now check if the extension was successfully installed
$ php -i | grep xhprof
$ # maybe restart your webserver or php-fpm...

Note: we need graphviz to generate callgraphs.

Laravel Sail environment

If you are using laravel sail, here's a setup for you:

$ sail up -d
$ sail artisan sail:publish
$ # in docker-compose.yml check wich php version is used under build->context (eg. ./docker/8.1)
$ # if you know the php-version you can type:
$ nano docker/<php-version>/Dockerfile
$ # find the block where all php extionsions are installed and add "php<php-version>-xhprof graphviz \"
$ # now you need to rebuild sail
$ sail down ; sail build --no-cache ; sail up -d # this may take a while...
$ # you can now check if the extension was successfully installed
$ sail php -i | grep xhprof

Note: The provided Laravel Sail Dockerfile already uses ondrejs ppa.

Install the Package

$ composer require laracraft-tech/laravel-xhprof --dev
$ php artisan vendor:publish --provider="LaracraftTech\LaravelXhprof\XHProfServiceProvider" --tag="config"

Install the UI

We are using the recommended fork by php.net from "preinheimer": https://www.php.net/manual/en/xhprof.requirements.php

$ mkdir public/vendor ; git clone [email protected]:preinheimer/xhprof.git ./public/vendor/xhprof
$ # if you havent already, I recommend adding public/vendor to your .gitignore
$ echo "/public/vendor" >> .gitignore

Database

Since the database table name, which the UI package is using behind to store and read data from the database, is hard coded to details and you already may have a table named like that, you may need to make some additional steps. If not, here at first the simple way:


In case you DON'T already HAVE an own details table in your database:

$ php artisan vendor:publish --provider="LaracraftTech\LaravelXhprof\XHProfServiceProvider" --tag="migrations"
$ php artisan migrate

In case you already HAVE an own details table in your database:

I recommend to just use a different database.

CREATE DATABASE xhprof;
USE xhprof;
CREATE TABLE IF NOT EXISTS `details` (
  `idcount` int(11) NOT NULL AUTO_INCREMENT,
  `id` char(64) NOT NULL,
  `url` varchar(255) DEFAULT NULL,
  `c_url` varchar(255) DEFAULT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `server name` varchar(64) DEFAULT NULL,
  `perfdata` mediumblob,
  `type` tinyint(4) DEFAULT NULL,
  `cookie` blob,
  `post` blob,
  `get` blob,
  `pmu` int(11) DEFAULT NULL,
  `wt` int(11) DEFAULT NULL,
  `cpu` int(11) DEFAULT NULL,
  `server_id` char(64) DEFAULT NULL,
  `aggregateCalls_include` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`idcount`),
  KEY `url` (`url`),
  KEY `c_url` (`c_url`),
  KEY `cpu` (`cpu`),
  KEY `wt` (`wt`),
  KEY `pmu` (`pmu`),
  KEY `timestamp` (`timestamp`),
  KEY `Aggregation of the last n entries by Servername` (`server name`(5),`timestamp`)
);

Note: you also need to create a user which has privileges on that new database!

Config

Now let's configure some settings!

$ cp public/vendor/xhprof/xhprof_lib/config.sample.php public/vendor/xhprof/xhprof_lib/config.php
$ # 1. change the db credentials to your needs
$ # 2. enable dot_binary section
$ # 3. if you're local, set $controlIPs to false
$ nano public/vendor/xhprof/xhprof_lib/config.php

Usage

Just set XHPROF_ENABLED=true in your .env file and now every request you make to your application gets profiled.
Visit <your-host>/vendor/xhprof/xhprof_html/ to see your profiling results.

Happy analysing!

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

laravel-xhprof's People

Contributors

ryun avatar sairahcaz 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.