Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i Analysis of loaded parts of Php code with xhprof / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • Php
  • Analysis of loaded parts of Php code with xhprof

Analysis of loaded parts of Php code with xhprof

xhprof is a tool that allows you to collect information both on the local machine and in production.

The choice fell on xhprof, since with certain additions, you can visually monitor the work of classes and build graphs.

1. Install on Ubuntu 14.04 // I won't change to a new one =)

The regular command did NOT fit, I don’t have this in the repositories (apt-get install xhprof), so I had to build it on my knee.

sudo apt-get install php-pear php5.6-dev php5.6-mcrypt

sudo php5enmod mcrypt

sudo pecl install xhprof-beta

Installation is carried out through pecl, and above are the necessary extensions for php and the mcrypt connection. Installation packages depend on the version of Linux and on the version of php.

2. For your version of php, set the definition in mods-available:

sudo nano /etc/php/5.6/mods-available/xhprof.ini

add lines to the file

extension=xhprof.so

If everything went right, then you can connect the xhprof module (for your version of php).

sudo php5enmod xhprof

sudo service apache2 restart

3. Checking the installed package :

php -i | grep xhprof

xhprof varsion
4. Getting Started :
After a successful installation and witchcraft, this design stopped throwing errors in the code.

<?php

// Initialize xhprof
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

foreach ([1,2,3] as $v) {
echo $v;
}

// Stop xhprof after program execution
$xhprof_data = xhprof_disable();

XHPROF_FLAGS_CPU - CPU time analysis

XHPROF_FLAGS_MEMORY - memory analysis

The usage is very simple, the code you need for debugging should be placed between xhprof_enable() and xhprof_disable(). $xhprof_data will contain all the information. But it is difficult for human understanding.

5. For more convenient processing of this information :

There is a ready-made interface for submitting shot information in human form. Download here . Or here . Or terminal:

cd /var/www; wget http://pecl.php.net/get/xhprof-0.9.4.tgz gzip -d xhprof-0.9.4.tgz tar -xvf xhprof-0.9.4.tar

You should unpack the contents of the archive into a directory that will be available as a domain. For example, on the local machine it is /var/www/xhprof-0.9.4

5.1. We start a local address (it will be xhprof.loc on apache):

sudo nano /etc/apache2/sites-available/xhprof.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName xhprof.loc
ServerAlias www.xhprof.loc
DocumentRoot /var/www/xhprof-0.9.4/xhprof_html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/xhprof-0.9.4/xhprof_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

sudo nano /etc/hosts

127.0.0.1 www.xhprof.loc
127.0.0.1 xhprof.loc

sudo service apache2 restart

As it is already clear, the working folder of this engine is xhprof_html . The front end looks like this:

xhprof_html

5.2. Usage in code :

For use, after xhprof_disable(), add lines defining the place where to dump the spent logs.

<?php

// Initialize xhprof
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

foreach ([1 ,2,3] as $v) {
    echo $v;
}

// Stop xhprof after program execution
$xhprof_data = xhprof_disable();

// Disable data with id " "
// Note that the path where we unpacked everything
include_once "/var/www/xhprof-0.9.4/xhprof_lib/utils/xhprof_lib.php";
include_once " /var/www/xhprof-0.9.4/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, " product");

product xhprof

Gives a lot of information on all running classes:

xhprof_info

6. Graphic report :

Also, xhprof allows you to generate a graphical report, which makes it clear what is knocking and where. This requires the installation of graphviz .

sudo apt-get install graphviz

graphviz

Used sources: source1 source2

31 October 18
1410
0

Comments

Name
E-mail
Rating
Review

Other articles from the category

25 April 2022

Create and download CSV in PHP

Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.

19 June 2019

ImageCMS Templates 4.10-4.12.1

Latest templates from ImageCMS 4.12, authorization is required to download.

26 January 2019

Long-term storage of the basket in the online store

Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.

17 January 2019

License key for ImageCMS 4.9-4.12.1 Pro and Pre

Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.

07 December 2018

$_SERVER[DOCUMENT_ROOT] in CLI or Cron

When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.

18 July 2018

Grouping conditions in an ORM Propel query (condition, combine)

Let's analyze the possibility of combining conditions in a query by groups in Propel. Consider an example of filtering by fields using ->condition() and ->combine().

14 June 2018

Authorization 1C on the site PHP_AUTH_USER on CentOS apache

Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .

21 May 2018

Joining an undeclared table in Propel or Join Custom Table Propel

The purpose of the article was to join (join) a table not declared in the schema (schema.xml) in propel2. Apparently a rare case or simply not enough documentation for this Propel ORM.

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R