Giter Site home page Giter Site logo

profiler's Introduction

Tideways PHP Library

PHP Client Library for Tideways PHP Profiler platform.

Installation

There are two ways to install the Profiler Client:

  1. Use Composer to install this library with:

     $ composer require tideways/profiler
    
  2. Download the single combined file from releases page.

The profiler class is monolithic intentionally to allow simple integration in all kinds of your projects.

Requirements

You need either the xhprof or tideways PHP extensions installed to allow profiling on PHP. For HHVM no additional requirements are necessary.

The Tideways Daemon (tidewaysd) has to be running on the production/staging machine that you are profiling, otherwise the collected data will be lost.

Integration

Tideways can be integrated in your application in two ways, either by configuration (Environment/INI variables) or programatically in PHP code.

Environment/INI Variables

The recommended method when using Tideways to monitor and profile web-requests is integration by configuration. It allows you to start collecting data without changing your application.

You need to configure the following INI settings (only when using Tideways PHP extension, does not work with XHProf):

tideways.api_key=api key here
tideways.sample_rate=10 ; 10% of requests get profiled

; if you use composer don't autoload the library
tideways.load_library=0

; if you want to start profiling without adding composer package
tideways.load_library=1

Or through Environment variables, for example in PHP-FPM Pool:

env[TIDEWAYS_APIKEY]=api key here
env[TIDEWAYS_SAMPLERATE]=10
env[TIDEWAYS_AUTO_START]=1

Programatical Integration

<?php

require_once 'vendor/autoload.php';

\Tideways\Profiler::start("api key here", 10); // 10% Sample-Rate

Configuration

Tideways follows The Twelve-Factor App rules and is configured via environment variables.

This allows you to configure the Profiler differently on each server without having to change the code.

  • TIDEWAYS_DISABLED controls if the profiler should be disabled on the server.
  • TIDEWAYS_SAMPLERATE controls the sample rate how often the profiler should sample full XHProf traces.
  • TIDEWAYS_DISABLE_SESSIONS controls if explicit developer sessions are allowed. They are enabled by default.

For example you can configure this in your PHP FPM Pool configuration:

env[TIDEWAYS_DISABLED] = 0
env[TIDEWAYS_SAMPLERATE] = 10
env[TIDEWAYS_DISABLE_SESSIONS] = 0

Framework Detection

Every request should be grouped by a transaction name that captures the name of the executed controller/action in your application. This is usually done with \Tideways\Profiler::setTransactionName(). For various popular frameworks we have added support to detect the transaction names automatically while profiling. To enable a framework just call \Tideways\Profiler::detectFrameworkTransaction with one of the following constants:

  • Tideways\Profiler::FRAMEWORK_ZEND_FRAMEWORK1 for Zend Framework1 apps
  • Tideways\Profiler::FRAMEWORK_ZEND_FRAMEWORK2 for Zend Framework2 apps
  • Tideways\Profiler::FRAMEWORK_SYMFONY2_FRAMEWORK for Symfony2 apps
  • Tideways\Profiler::FRAMEWORK_SHOPWARE for Shopware apps
  • Tideways\Profiler::FRAMEWORK_OXID for Oxid apps
  • Tideways\Profiler::FRAMEWORK_WORDPRESS for Wordpress apps

We are planning to add more frameworks as we improve the library.

Custom Variables

You can add custom variables to every full profiling trace:

<?php

\Tideways\Profiler::setCustomVariable('url', $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI']);
\Tideways\Profiler::setCustomVariable('mysql_thread_id', mysql_thread_id());

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.