• Date: November 7, 2011
  • Author: Slawek Lukasiewicz
  • Comments: 2 Comments
  • Category: PHP

Application profiling can help us determine bottlenecks and possible problems during development. But sometimes we also need to diagnose problems in production environment. Frequent performance problems are connected with functions and methods using too much memory.

If we want to track functions with too high memory consumption, we can use Memtrack extension. With this extension we can set admissible memory limit, and when some function exceed it – warning will be sent.

Memtrack is PECL extension, so installation is straightforward:

pecl install memtrack

Configuration is also easy.

memtrack.enabled = 1 ; enabling Memtrack extension
memtrack.soft_limit = int ; set memory limit for functions

More configuration options can be found here.



memtrack.enabled = 1
memtrack.soft_limit = 1M

PHP code

function tooHighMemoryConsumption() {
    $someData = array();
    for ($i = 0; $i < 10000; $i++) {
    	$someData[] = sha1('a');
    return $someData;
$data = tooHighMemoryConsumption();

Generated warning

[memtrack] [pid 10408] user function tooHighMemoryConsumption() executed in PATH on line 10 allocated 1572864 bytes

In above log we can found information about process, function (name and information about type – function can be internal or user defined), file path, line and memory usage.

2 Responses to “PHP application diagnostics – Memtrack”

  1. pkalisz says:

    Nice tool, but are there any other useful features besides memory exceed warnings?

Leave a Reply →