GithubHelp home page GithubHelp logo

classicvalues / pecl-php-memtrack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from php/pecl-php-memtrack

1.0 0.0 0.0 13 KB

PHP extension to watch (unusually high) memory consumption in PHP scripts

Home Page: http://pecl.php.net/package/memtrack

C 100.00%

pecl-php-memtrack's Introduction

memtrack PHP extension
======================

1. How it works
---------------

memtrack is a PHP extension that tracks memory consumption in PHP scripts 
and produces reports (warnings) when the consumption reaches certain levels 
set by the user.

memtrack replaces default executor function by its own function which 
compares memory usage before and after running the original executor, 
this way we can tell how much the memory usage has changed.

2. Configuration
----------------

The following INI options are available at the moment:

 memtrack.enabled - Boolean flag, which enables or disabled the extension.
                    Default value is 0, i.e. disabled.

 memtrack.soft_limit - A soft memory limit. The extension produces a warning when a 
                       function reaches it, if the function is not ignored.
					   Default value is 0.

 memtrack.hard_limit - A hard memory limit. The extension produces a warning when a
                       function reaches it, whether or not the function is listed 
					   in memtrack.ignore_functions.
					   Default value is 0.

 memtrack.ignore_functions - A comma- or whitespace-separated list of functions, 
                             which are to be ignored. The values are case-insensitive, 
							 for class methods use Class::method syntax.

 memtrack.vm_limit - Virtual memory size limit (set on a process), which is measured on shutdown only.
					 The extension produces a warning when the limit is reached.
					 NB: Available only on Linux.
					 Default value is 0.

3. Examples
-----------

# php -d memtrack.enabled=1 -d memtrack.soft_limit=10000 -d memtrack.ignore_functions="" -r '$a = str_repeat("aaaaaaaa", 100000);'

Warning: [memtrack] [pid 26154] internal function str_repeat() executed in Command line code on line 1 allocated 1048576 bytes in Command line code on line 1

# /tmp/1.php
<?php
function foo() {
    $a = array();
    for ($i = 0; $i < 10000; $i++) $a[] = "test";
    return $a;
}
$arr = foo();
?>

# php -d memtrack.enabled=1 -d memtrack.soft_limit=1M -d memtrack.ignore_functions="" -d memtrack.vm_limit=3M /tmp/1.php

Warning: [memtrack] [pid 26177] user function foo() executed in /tmp/1.php on line 7 allocated 4194304 bytes in /tmp/1.php on line 0
Warning: [memtrack] [pid 26177] virtual memory usage on shutdown: 32911360 bytes in Unknown on line 0


4. Compatibility with other extensions
--------------------------------------

memtrack is not a Zend extension, hence it doesn't have any extensions compatibility problems.
Though it was noticed that running Zend Optimizer with memtrack produces op_array's without any 
information left, so memtrack is unable to fetch function and class names, as well as filenames 
and line numbers, which makes memtrack pretty much useless.

pecl-php-memtrack's People

Contributors

pierrejoye avatar tony2001 avatar

Stargazers

 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.