Easy XHProf setup to profile your laravel application!

Overview

Logo Laravel XHProf

Total Downloads 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 need to install the php extension. It's highly recommended using ondrejs ppa. It's well maintained and provides quite all php versions.

PHP 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

Note: we need graphviz to generate callgraphs.

Laravel Sail

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 sairahcaz/laravel-xhprof --dev
$ php artisan vendor:publish --provider="Sairahcaz\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 first the simple way:


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

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

In case you 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 your 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.

You might also like...
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Integrate your PHP application with your HTTP caching proxy

FOSHttpCache Introduction This library integrates your PHP applications with HTTP caching proxies such as Varnish. Use this library to send invalidati

Task for GrumPHP that adds CSS linting support with stylelint. An easy way to enforce convention and avoid errors in your styles

grumphp-stylelint-task Installation Stylelint is a static analysis tool for styles. A mighty, modern linter that helps you avoid errors and enforce co

ConFOMO is a simple tool that makes it easy to track your friends at conferences.
ConFOMO is a simple tool that makes it easy to track your friends at conferences.

Connecting your online community with the real world, one conference at a time. Built in 4 hours to help me track who I wanted to meet at Laracon 2014

📦 An easy way to share the data from your backend to the JavaScript.

Laravel Shared Data ✨ Introduction Laravel Shared Data provides an easy way to share the data from your backend to the JavaScript. 🚀 Quick start Inst

NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features.
NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features.

NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features

A simple and easy-to-use enumeration extension package to help you manage enumerations in your project more conveniently

A simple and easy-to-use enumeration extension package to help you manage enumerations in your project more conveniently

This plugin can be embedded in PHP application to give the web application specific routes/href

Routes Plugin PHP This plugin can be embedded in PHP application to give the web application specific routes/href location and for entering specific/l

Laravel Larex lets you translate your whole Laravel application with a single CSV file.
Laravel Larex lets you translate your whole Laravel application with a single CSV file.

Laravel Larex Laravel Larex lets you translate your whole Laravel application with a single CSV file. You can import translation entries from lang fol

Comments
  • How about encapsulating the frontend part?

    How about encapsulating the frontend part?

    Hey

    I have some ideas on how to make the package better considering you depend on https://github.com/preinheimer/xhprof - one of the ugliest things I have ever seen lol.

    How about making 2 things:

    • Encapsulate the https://github.com/preinheimer/xhprof into a resource package to avoid repository clone operation.
    • Make everything configurable in a standard laravel way - today we have to keep 2 copies of the configuration, one for the application and one for the cloned ignored directory.

    We can start on these changes and move forward step by step making the profiling process great.

    opened by a-bashtannik 6
  • Fix the migration

    Fix the migration

    While working with postgresql, I faced a small problem running the migration,

       INFO  Running migrations.
    
      2022_10_25_094737_create_xhprof_table .................................................................................................. 42ms FAIL
    
       Illuminate\Database\QueryException
    
      SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "ON"
    LINE 1: ...hout time zone not null default CURRENT_TIMESTAMP ON UPDATE ...
                                                                 ^ (SQL: create table "details" ("idcount" bigserial primary key not null, "id" char(64) not null, "url" char(255) null, "c_url" char(255) null, "timestamp" timestamp(0) without time zone not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "server name" char(64) null, "perfdata" bytea null, "type" smallint null, "cookie" bytea null, "post" bytea null, "get" bytea null, "pmu" integer null, "wt" integer null, "cpu" integer null, "server_id" char(64) null, "aggregateCalls_include" char(255) null))
    
      at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
        756â–•         // If an exception occurs when attempting to run a query, we'll format the error
        757â–•         // message to include the bindings with SQL, which will make this exception a
        758â–•         // lot more helpful to the developer instead of just the database's errors.
        759â–•         catch (Exception $e) {
      ➜ 760▕             throw new QueryException(
        761â–•                 $query, $this->prepareBindings($bindings), $e
        762â–•             );
        763â–•         }
        764â–•     }
    
          +9 vendor frames
      10  database/migrations/2022_10_25_094737_create_xhprof_table.php:41
          Illuminate\Support\Facades\Facade::__callStatic("create")
    
          +26 vendor frames
      37  artisan:37
          Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    

    so I guess it is better to change https://github.com/laracraft-tech/laravel-xhprof/blob/08e1d80c22697bd04e98b584e02d63a4bdbc8071/database/migrations/create_xhprof_table.php.stub#L21

    to

    $table->timestamp('timestamp')->useCurrent()->useCurrentOnUpdate();
    

    which in my case fixed the problem :D

    opened by zaherg 1
  • Fix too short field length issue

    Fix too short field length issue

    In some cases, the collected data is more than 65 KB, which is the default for MySQL BLOB data. There is no other built-in way to define LONGBLOB in Laravel 9, so I just use raw statements.

    This PR fixes the error for new migrations.

    opened by a-bashtannik 0
Releases(v1.0.8)
Owner
Zacharias Creutznacher
Zacharias Creutznacher
PHP Project - Export your profile to vCard file

KamVCard PHP v1.00 Easy to have your own vCard file, fill in the form and hit the "Export" button UPDATE : Now you can add your picture too ! Preview

Med Reda Kamal 3 Nov 6, 2022
Unterschiedliche Versand-Profile für den PHPMailer in REDAXO (REXMailer) für unterschiedliche Absende-Adressen und/oder SMTP-Postfächer

Mailer Profile für REDAXO 5 Erweitert das Core-Addon phpmailer um die Möglichkeit, unterschiedliche Absende-Profile und Postfächer-Konfigurationen vor

alex+ Informationsdesign 7 Dec 22, 2022
My solution use PHP with a class for easy setup

My solution use PHP with a class for easy setup. It accepts requests with the get method just passing the username and password as well as the ip and http port of the Proxmox server. Just needing a web server.

Full Monitoring 2 Jan 15, 2022
BreadBooru is a light, quick, and easy to setup imageboard with themes, images, and video support

BreadBooru a bad imageboard, that has nothing to do with (dan/gel)booru, and yet still has booru in the name BreadBooru is a light, quick, and easy to

bread 2 Jan 22, 2022
Run the following commands in your terminal to setup the project

Run the following commands in your terminal to setup the project You must have the LAMP installed on your system git clone https://github.com/Bashar-A

null 1 Nov 6, 2021
Setup Docker Para Projetos Laravel 9 com PHP 8

Setup Docker Para Projetos Laravel 9 com PHP 8

EspecializaTi 56 Dec 6, 2022
This is a setup for a Tor based shared web hosting server

General Information: This is a setup for a Tor based shared hosting server. It is provided as is and before putting it into production you should make

Daniel Winzen 312 Dec 24, 2022
Production ready scalable Magento setup utilizing the docker

Magento docker image Requirements This docker image expects 2 other linked containers to work . Mysqldb or Mariadb linked as 'db' Memcached linked as

Paim pozhil 49 Jun 21, 2021
composer plugin for a better frontend setup

node-composer composer plugin for a better frontend setup PHP projects mostly are Web-Applications. Many Web-Applications also need a frontend part wh

Marius Büscher 5 Jul 26, 2022
This package makes it easy to add early access mode to your existing application.

This package makes it easy to add early access mode to your existing application. This is useful for when you want to launch a product and need to gat

Neo 174 Nov 26, 2022