php.net |  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
Votes:8
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tim at digicol dot de
New email:
PHP Version: OS:

 

 [2008-12-17 15:11 UTC] tim at digicol dot de
Description:
------------
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:
---------------
<?php

// 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...

Patches

Pull Requests

History

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

OS:
FreeBSD 7.0-RELEASE-p4 FreeBSD 7.0-RELEASE-p4

PHP:
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] derick@php.net
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
http://snaps.php.net/.
 
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] pajoye@php.net
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
32bit:

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

And why was it closed then?
 [2009-09-02 11:30 UTC] jani@php.net
Same issue as in bug #47285	
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC