Skip to main content

SPX | Best Php Training Trivandrum

SPX.


Showcase

Requirements

Installation

Prerequisites

Install the extension

Development status

Basic usage

CLI script

HTTP request

Advanced usage

Parameters

Available parameters

NameDefaultDescription
SPX_KEY The secret key, required for HTTP request profiling.
SPX_ENABLED0Whether to enable SPX profiler (i.e. triggering profiling). When disabled there is no performance impact on your application.
SPX_BUILTINS0Whether to instrument internal functions.
SPX_DEPTH0The stack depth at which profiling must stop (i.e. aggregate measures of deeper calls). 0 (default value) means unlimited.
SPX_METRICSwt,zmComma separated list of available metric keys to monitor. All output types, except Google's Trace Event Format, take advantage of multi-metric profiling.
SPX_OUTPUTfpSelected output key.
SPX_OUTPUT_FILECLI only. Custom output file. If not specified it will be generated in /tmp and displayed on STDERR at the end of the script.
SPX_FP_FOCUSwtMetric key for flat profile sort.
SPX_FP_INC0Whether to sort functions by inclusive value instead of exclusive value in flat profile.
SPX_FP_REL0Whether to display metric values as relative (i.e. percentage) in flat profile.
SPX_FP_LIMIT10The flat profile size (i.e. top N shown functions).
SPX_FP_LIVE0For CLI only. Whether to enabled flat profile live refresh. Since it uses ANSI escape sequences, it uses STDOUT as output, replacing script output (both STDOUT & STDERR). It also does not work if you have specified a custom output file.
SPX_TRACE_SAFE0The trace file is by default written in a way to enforce accuracy, but in case of process crash (e.g. segfault) some logs could be lost. If you want to enforce security (e.g. to find the last event before a crash) you just have to set this parameter to 1.

Setting parameters for CLI script

Setting parameters for HTTP request

HTTP

Security concern

Configuration

NameDefaultChangeableDescription
 spx.http_enabled0PHP_INI_SYSTEMWhether to enable profiling of HTTP requests.
 spx.http_keyPHP_INI_SYSTEMThe secret key. You can use the following command to generate a 16 bytes random key as an hex string: openssl rand -hex 16.
 spx.http_ip_varREMOTE_ADDRPHP_INI_SYSTEMThe $_SERVER key holding the client IP address. Overriding the default value is required when your application is behind a reverse proxy.
 spx.http_ip_whitelistPHP_INI_SYSTEMThe IP address white list as a comma separated list of IP addresses.
Private environment
spx.http_enabled=1
spx.http_key="dev"
spx.http_ip_whitelist="127.0.0.1"

Best practices

Metrics

Available metrics

KeyNameDescription
wtWall TimeThe absolute elapsed time.
ctCPU TimeThe time spent while running on CPU.
itIdle TimeThe time spent off CPU, that means waiting for CPU, I/O completion, a lock acquisition... or explicitly sleeping.
zmZend Engine memoryZend Engine memory usage. Equivalent to memory_get_usage(false).
zrZend Engine root buffer lengthRoot buffer length, see explanation here. It could be helpful to track pressure on garbage collector.
zoZend Engine object countNumber of objects currently held by user code.
zeZend Engine error countNumber of raised PHP errors.
ioI/O (reads + writes)Bytes read or written while performing I/O.
iorI/O (reads)Bytes read while performing I/O.
iowI/O (writes)Bytes written while performing I/O.

Outputs

Available outputs

KeyNameSupported metricsMulti metricsDescription
fpFlat profileAllYesThe flat profile provided by SPX. It is the default output and is directly printed on STDOUT (CLI) or in place of response body (HTTP).
cgCallgrindAllYesA file in Callgrind format to be analyzed with KCachegrind or similar.
gteGoogle's Trace Event FormatTime metricsNoA file in Google's Trace Event Format to be analyzed with Chromium's / Chrome's about:tracing.
traceTrace fileAllYesA custom format (human readable text) trace file.

Examples

HTTP request / KCachegrind

KCachegrind

HTTP request / about:tracing

about:tracing

CLI script / trace file

$ SPX_ENABLED=1 SPX_OUTPUT=trace SPX_OUTPUT_FILE=trace.txt ./bin/console > /dev/null && head -20 trace.txt && echo ... && tail -20 trace.txt
 Wall Time                      | ZE memory                      |
 Cum.     | Inc.     | Exc.     | Cum.     | Inc.     | Exc.     | Depth    | Function
----------+----------+----------+----------+----------+----------+----------+----------
      0us |      0us |      0us |       0B |       0B |       0B |        1 | +/home/sylvain/dev/sf_app/bin/console
    994us |      0us |      0us |    1.3KB |       0B |       0B |        2 |  +/home/sylvain/dev/sf_app/vendor/autoload.php
    1.3ms |      0us |      0us |   11.3KB |       0B |       0B |        3 |   +/home/sylvain/dev/sf_app/vendor/composer/autoload_real.php
    1.3ms |      3us |      3us |   11.3KB |       0B |       0B |        3 |   -/home/sylvain/dev/sf_app/vendor/composer/autoload_real.php
    1.3ms |      0us |      0us |   10.9KB |       0B |       0B |        3 |   +ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::getLoader
    1.3ms |      0us |      0us |   11.9KB |       0B |       0B |        4 |    +ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::loadClassLoader
    2.3ms |      0us |      0us |   51.6KB |       0B |       0B |        5 |     +ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::/home/sylvain/dev/sf_app/vendor/composer/ClassLoader.php
    2.3ms |      1us |      1us |   51.6KB |       0B |       0B |        5 |     -ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::/home/sylvain/dev/sf_app/vendor/composer/ClassLoader.php
    2.3ms |    1.0ms |    1.0ms |   51.3KB |   39.4KB |   39.4KB |        4 |    -ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::loadClassLoader
    2.7ms |      0us |      0us |   91.5KB |       0B |       0B |        4 |    +ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::/home/sylvain/dev/sf_app/vendor/composer/autoload_static.php
    2.7ms |      1us |      1us |   91.5KB |       0B |       0B |        4 |    -ComposerAutoloaderInita657e2f64bf98eb70db4e96bba0d4058::/home/sylvain/dev/sf_app/vendor/composer/autoload_static.php
    2.7ms |      0us |      0us |   91.2KB |       0B |       0B |        4 |    +Composer\Autoload\ComposerStaticInita657e2f64bf98eb70db4e96bba0d4058::getInitializer
    2.7ms |      5us |      5us |   92.0KB |     856B |     856B |        4 |    -Composer\Autoload\ComposerStaticInita657e2f64bf98eb70db4e96bba0d4058::getInitializer
    2.7ms |      0us |      0us |   92.0KB |       0B |       0B |        4 |    +Composer\Autoload\ClassLoader::Composer\Autoload\{closure}
    2.7ms |      5us |      5us |   91.2KB |    -856B |    -856B |        4 |    -Composer\Autoload\ClassLoader::Composer\Autoload\{closure}
    2.7ms |      0us |      0us |   91.2KB |       0B |       0B |        4 |    +Composer\Autoload\ClassLoader::register
    2.7ms |      6us |      6us |   91.3KB |     128B |     128B |        4 |    -Composer\Autoload\ClassLoader::register
...
  126.6ms |   24.6ms |     10us |    6.1MB |  874.8KB |     488B |        4 |    -Symfony\Component\Console\Application::doRun
  126.6ms |   97.2ms |     27us |    6.1MB |    4.9MB |       0B |        3 |   -Symfony\Bundle\FrameworkBundle\Console\Application::doRun
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        3 |   +Symfony\Component\Debug\ErrorHandler::handleFatalError
  126.6ms |      4us |      4us |    6.1MB |  -12.0KB |  -12.0KB |        3 |   -Symfony\Component\Debug\ErrorHandler::handleFatalError
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        3 |   +Monolog\Handler\AbstractHandler::__destruct
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        4 |    +Symfony\Bridge\Monolog\Handler\ConsoleHandler::close
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        5 |     +Monolog\Handler\AbstractHandler::close
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        5 |     -Monolog\Handler\AbstractHandler::close
  126.6ms |      1us |      1us |    6.1MB |       0B |       0B |        4 |    -Symfony\Bridge\Monolog\Handler\ConsoleHandler::close
  126.6ms |      3us |      2us |    6.1MB |       0B |       0B |        3 |   -Monolog\Handler\AbstractHandler::__destruct
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        3 |   +Monolog\Handler\AbstractHandler::__destruct
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        4 |    +Monolog\Handler\AbstractHandler::close
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        4 |    -Monolog\Handler\AbstractHandler::close
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        3 |   -Monolog\Handler\AbstractHandler::__destruct
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        3 |   +Monolog\Handler\AbstractHandler::__destruct
  126.6ms |      0us |      0us |    6.1MB |       0B |       0B |        4 |    +Monolog\Handler\StreamHandler::close
  126.6ms |      2us |      2us |    6.1MB |       0B |       0B |        4 |    -Monolog\Handler\StreamHandler::close
  126.6ms |      2us |      0us |    6.1MB |       0B |       0B |        3 |   -Monolog\Handler\AbstractHandler::__destruct
  126.6ms |  105.6ms |     38us |    6.1MB |    5.2MB |     624B |        2 |  -Symfony\Component\Console\Application::run
  126.6ms |  126.6ms |    1.0ms |    6.1MB |    6.1MB |    1.6KB |        1 | -/home/sylvain/dev/sf_app/bin/console

Credits

Comments

Popular posts from this blog

Memory leak in 7.x json_decode()? Best Php Training Trivandrum

Memory leak in 7.x json_decode()? There appears to be a memory leak in 7.x json_decode(). I've uploaded a huge JSON file to demonstrate the problem. Here is the sample code: <?php echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; $json = json_decode(file_get_contents('http://zaremedia.com/big.json')); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; unset($json); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; Below is output from 7.x and then 5.6: // Running on 7.0 and 7.1 349608 : 2097152 27245512 : 29360128 375552 : 29360128 The process starts with 0.3mb used / 2.0mb allocated. After json_decode(), it's 27.2 / 29.4mb, after unset, it's 3.7mb / 29.4mb -- The second value (memory allocated by php via emalloc()) has not been freed, though PHP's gc has correctly freed up the object usage. // Running on 5.6 221136 : 262144 31577064 : 35913728 420104 : 86507

How do I deploy my Symfony API - - Deploy best php training trivandrum

How do I deploy my Symfony API -  - Deploy This is the forth post from a series of posts that will describe the whole deploy process from development to production.  The first article is available  here , the second  here  and the third  here . After covering the steps 1-3 and having prepared our infrastructure, we can see how to  deploy  our application to production. Almost the same approach can be used to deploy not only to production but also to test environments. Workflow Different "git push" operation should trigger different actions. Just as example a push to  master  should trigger a deploy to production, while other branches may trigger a deploy to a test environment, or not trigger deploys at all. I've used  Circe CI Workflows  to manage this set of decisions. Workflows are just another section from the same  .circleci/config.yml  file and here they are: workflows: version: 2 build_and_deploy-workflow: jobs: - build - d

A DateTimePeriod library for working with temporal intervals php training trivandrum

An implementation of the datetime period type for working with temporal intervals. The library includes the full set of relations on intervals defined by  Allen's Interval Algebra . For further information see the "Usage" and "How it works" paragraphs. Requirements PHP 7.1+ Installation $ composer require pwm/datetime-period Usage Creation: $start = new DateTimeImmutable ( ' 2010-10-10T10:10:10+00:00 ' ); $end = new DateTimeImmutable ( ' 2011-11-11T11:11:11+00:00 ' ); $period = new DateTimePeriod ( $start , $end ); // Start/end instants and their interval $start = $period -> getStart(); // DateTimeImmutable('2010-10-10T10:10:10+00:00') $end = $period -> getEnd(); // DateTimeImmutable('2011-11-11T11:11:11+00:00') $interval = $period -> getInterval(); // DateInterval('P1Y1M1DT1H1M1S') Restrictions: // Throws TimeZoneMismatch exception new DateTimePeriod ( new Da