PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics

go to bug id or search bugs for  

Generating a valgrind log

Important!

To get a meaningful log you must have PHP configured with --enable-debug and disable Zend memory manager.

Disabling Zend MM

Zend Engine uses its own routines to optimize memory management, but because of this valgrind cannot see most of the memory issues. You must disable Zend memory manager before running PHP with valgrind. In order to do this you need to set USE_ZEND_ALLOC environment variable to 0.

Use

export USE_ZEND_ALLOC=0
or
setenv USE_ZEND_ALLOC 0
(the syntax depends on what your shell supports).

This works since PHP 5.2 (with debug builds only), in older versions you had to reconfigure PHP with --disable-zend-memory-manager option.

Running PHP CLI or PHP CGI through valgrind

To generate the valgrind log using PHP CLI/CGI, you need to execute the following command:

 
 valgrind --tool=memcheck --num-callers=30 --log-file-exactly=php.log /path/to/php-cli script.php
 

This should put the log into php.log file in the current working directory.

Running PHP Apache module through valgrind

If you compiled PHP and Apache statically, make sure the Apache binary is not stripped after make install, otherwise you lose the required debug info. To check it, run file /path/to/httpd, it should output something like this (notice "not stripped"):

 
 # file /usr/local/apache2/bin/httpd
 /usr/local/apache2/bin/httpd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped
 

To generate the valgrind log using PHP as Apache module, you need to run the Apache itself under valgrind:

 
 valgrind --tool=memcheck --num-callers=30 --log-file-exactly=apache.log /usr/local/apache/bin/httpd -X
 

This should put all the memory errors into into apache.log file.


show source 

PHP Copyright © 2001-2008 The PHP Group
All rights reserved.
Last updated: Tue Nov 27 09:02:45 2007 UTC