|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46889 Memory leak in strtotime()
Submitted: 2008-12-17 15:11 UTC Modified: 2009-09-02 11:30 UTC
Avg. Score:4.0 ± 1.4
Reproduced:6 of 7 (85.7%)
Same Version:6 (100.0%)
Same OS:4 (66.7%)
From: tim at digicol dot de Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.8 OS: *
Private report: No CVE-ID: None
 [2008-12-17 15:11 UTC] tim at digicol dot de
With PHP 5.2.8, strtotime() on my Linux box leaks memory; we've 
noticed it because we're using long-running scripts with the PHP CLI. 
In our case, the PHP processes grew to hundreds of MB RAM usage within 
minutes. This is not the case with PHP 5.2.6.

The funny thing is that neither memory_get_usage(false) nor 
memory_get_usage(true) report the actual memory usage; here's a line 
from top:

22728 digicol   25   0  258m 218m 6928 R 75.4 43.4   0:42.91 php

... while the PHP functions report at the same time:

memory_get_usage(false): 1738020
memory_get_usage(true):  1835008

What's also funny is that the default "memory_limit = 128M" setting 
doesn't help: PHP doesn't notice that this much RAM is being 
used and so doesn't kill the script. (But I can trigger the memory 
limit as usual with other PHP scripts, so PHP's memory limit isn't 
entirely broken.)

I tested with an unchanged copy of php.ini-recommended.

My configure string:

'./configure'  '--with-apxs2=/usr/bin/apxs2' '--enable-exif' '--
enable-ftp' '--enable-mbregex' '--enable-mbstring=all' '--enable-
pcntl' '--enable-soap' '--enable-zip' '--with-zlib' '--with-curl' '--
with-freetype-dir=/usr' '--with-gd' '--with-jpeg-dir=/usr' '--with-
ldap' '--with-mysqli' '--with-
oci8=instantclient,/usr/local/lib/instantclient' '--enable-sigchild' 
'--with-png-dir=/usr' '--with-xsl' '--with-mcrypt'

This is Debian Linux 4.0, running in VMware Fusion on an Intel Mac.

Thanks a lot for looking into this, and for the great work on PHP!

Reproduce code:

// Run with the PHP CLI on the Linux shell...
// WARNING: If this bug affects you as well, your machine
// might start swapping within just a few seconds!

while (true)
    strtotime('2008-12-16 19:48:27');


Expected result:
No increase in memory usage.

Actual result:
Memory usage is increasing dramatically - on my box, the process is 
growing by 100 MB per second...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 11:12 UTC] martin at 925 dot dk
Reproduced here.

FreeBSD 7.0-RELEASE-p4 FreeBSD 7.0-RELEASE-p4

PHP 5.2.8 (cli) (built: Dec  8 2008 19:11:49) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
 [2008-12-18 14:57 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2008-12-19 14:11 UTC] tim at digicol dot de
I have verified that this bug is fixed in the PHP snapshot  php5.2-
200812191130.tar.bz2. Thanks a lot!
 [2009-07-03 08:28 UTC]
Where went this comment:

[2009-06-26 08:14:21] strucken at web dot de

Without using the second parameter of strtotime the memory leak is
fixed. But memory usage is still increasing when I execute the following
under windows (reproduces with 5.2.8, 5.2.9 and 5.2.10 under windows xp
and windows server 2003) until I reach the 2 GB limit of my windows

for( $i = 1; ; $i++ )
   strtotime( '+1 week', $i );

And why was it closed then?
 [2009-09-02 11:30 UTC]
Same issue as in bug #47285	
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 03:01:31 2024 UTC