Bug #71375 [NEW]: Memory not released from token_get_all()

From: Date: Thu, 14 Jan 2016 22:11:43 +0000
Subject: Bug #71375 [NEW]: Memory not released from token_get_all()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198656@lists.php.net to get a copy of this message
From:             pete at peteward dot net
Operating system: Centos Linux 7.0
PHP version:      7.0.2
Package:          Performance problem
Bug Type:         Bug
Bug description:Memory not released from token_get_all()

Description:
------------
Memory leaked from token_get_all() is much worse in php 7.x than in
5.x.

I have a large Symfony app with a container file string which when
passed through token_get_all() hangs on to a large amount of it's
consumed memory, despite the peak consumption being less.

I haven't managed to identify which tokens are causing this as a basic
very large string didn't have this issue, however the test script below
shows how it works with the 'real' content (a symfony container).



Test script:
---------------
<?php

printMemory();
$string =
file_get_contents('http://dev.radiancedaily.com/appDevDebugProjectContainer.txt');
printMemory();
getAllTokensInScope($string);
printMemory();

function printMemory() {
    $mem = str_pad(round((memory_get_usage(true)/1024/1024)), 3, " ",
STR_PAD_LEFT) . "MB " .
           str_pad(round((memory_get_peak_usage(true)/1024/1024)), 3, "
", STR_PAD_LEFT) . "MB ";
    print $mem . PHP_EOL;
}

function getAllTokensInScope($string) {
    $something = token_get_all($string);
}

Expected result:
----------------
Memory should be released outside of the scope of the function from
which it's called.

PHP 5.4 and 5.6:

$ php -v
PHP 5.6.14-0+deb8u1 (cli) (built: Oct  4 2015 16:13:10) 
Copyright (c) 1997-2015 The PHP Group

$ php test.php 
  0MB   0MB 
  3MB   3MB 
 11MB 210MB 


Actual result:
--------------
Most of the memory is not released.

$ php -v
PHP 7.0.2 (cli) (built: Jan  9 2016 14:00:11) ( NTS )
Copyright (c) 1997-2015 The PHP Group

$ php test.php 
  2MB   2MB 
  7MB   7MB 
111MB 130MB 



-- 
Edit bug report at https://bugs.php.net/bug.php?id=71375&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71375&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71375&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71375&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71375&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71375&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71375&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71375&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71375&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71375&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71375&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71375&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71375&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71375&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71375&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71375&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71375&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71375&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71375&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71375&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71375&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#198656) next »