|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67374 Integer Overflow in Memory Usage Functions
Submitted: 2014-06-03 14:42 UTC Modified: 2017-03-16 20:24 UTC
Avg. Score:4.2 ± 0.7
Reproduced:5 of 6 (83.3%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: johannesdahse at gmx dot de Assigned: nikic (profile)
Status: Closed Package: PHP options/info functions
PHP Version: 5.5.13 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
40 - 33 = ?
Subscribe to this entry?

 [2014-06-03 14:42 UTC] johannesdahse at gmx dot de
The memory usage functions memory_get_usage() and memory_get_peak_usage() are limited by INTEGER and can only store the memory usage of 2.147 GB. This results in false reports for higher memory usage.

Tested on Windows 7 64bit, PHP 5.5.13 (64bit and 32bit version).

Test script:
ini_set("memory_limit", "3G");

$a = array();
for($i=0; $i<22; $i++)
	$a[$i] = str_repeat("A", 100000000);

echo memory_get_peak_usage();

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-05 23:18 UTC]
-Type: Bug +Type: Feature/Change Request
 [2014-07-05 23:18 UTC]
I don't use windows often.
AFAIK, int is 32bit under windows regardless of architecture. Therefore, overflow is spec.

Is there any clean/feasible solution? Anyone?
 [2014-08-26 12:19 UTC] arie_dejong at msn dot com
You can increase the limit by using the negative integer.

$bytes = memory_get_peak_usage();
if($bytes < 0){
	$bytes = PHP_INT_MAX + ($bytes - ~PHP_INT_MAX);
 [2015-11-05 08:41 UTC] samuel dot chemla at orange dot com

any new on this ?

memory_get_peak_usage() should return an int, which should be 64bit on 64bit systems, but it appears to be 32bit.

Any reason why ?

NB: I'm on PHP 5.5.30 x64 build on Windows 7 x64
 [2015-11-05 09:01 UTC] samuel dot chemla at orange dot com
By the way this shoud be a bug, not a feature request...
 [2017-03-16 20:24 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-03-16 20:24 UTC]
PHP 7 supports 64bit integers on LLP64 platforms. Of course you'll still get an overflow on 32bit builds, but there isn't much we can do about that.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 00:01:24 2021 UTC