ID: 33614
Updated by: [EMAIL PROTECTED]
Reported By: nickj-phpbugs at nickj dot org
-Status: Open
+Status: Feedback
Bug Type: Date/time related
Operating System: Debian Woody GNU/Linux 3.0r6
PHP Version: 5CVS-2005-07-08 (dev)
New Comment:
So where is the leak itself?
Configure PHP with --enable-memory-limit and use memory_get_usage() to
see PHPs memory usage.
Btw, PHP uses Zend memory manager which *reports* about memleaks and
cares about them on his own. So, in case of memleak you'll see an error
message.
Previous Comments:
------------------------------------------------------------------------
[2005-07-08 08:25:55] nickj-phpbugs at nickj dot org
Description:
------------
Encountering a memory leak, possibly in date/time related code.
Running this script:
=================================================================
<?php
// tell us about all errors.
error_reporting(E_ALL);
define ("START_YEAR", 1971);
define ("END_YEAR", 2038);
function test_strtotime($request) {
for ($i=1; ; $i++) {
// start at year START_YEAR, bail out at year END_YEAR
$tStamp = mktime (17,17,17,1,$i,START_YEAR);
if (date("Y", $tStamp) == END_YEAR) break;
$strtotime_timestamp = strtotime ($request, $tStamp);
if (strftime("%r %B %d %Y", $strtotime_timestamp) != date ("h:i:s A
F d Y", $strtotime_timestamp)) {
print "Mismatch: $i $tStamp\n";
}
}
}
$days = array ("Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday");
for ($i=1; $i<500; $i++) {
putenv("TZ=Australia/Sydney");
foreach ($days as $day) {
test_strtotime($day);
}
}
?>
=================================================================
What's different to various other scripts I've run before to test
date/time code is this line:
> if (strftime("%r %B %d %Y", $strtotime_timestamp) != date ("h:i:s A F
d Y", $strtotime_timestamp))
So, something about this may possibly be the culprit.
Here's what I see on a Linux box whilst running this:
=================================================================
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:46:29 EST 2005
total used free shared buffers
cached
Mem: 452324 449108 3216 0 13016
325608
-/+ buffers/cache: 110484 341840
Swap: 787144 0 787144
root 1906 99.9 9.7 46796 44012 ttyp1 R+ 15:46 0:15
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:46:37 EST 2005
total used free shared buffers
cached
Mem: 452324 449516 2808 0 9904
307260
-/+ buffers/cache: 132352 319972
Swap: 787144 0 787144
root 1906 99.9 14.5 68728 65944 ttyp1 R+ 15:46 0:23
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:46:52 EST 2005
total used free shared buffers
cached
Mem: 452324 449276 3048 0 6160
270252
-/+ buffers/cache: 172864 279460
Swap: 787144 0 787144
root 1906 99.9 23.6 109604 106820 ttyp1 R+ 15:46 0:38
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:47:23 EST 2005
total used free shared buffers
cached
Mem: 452324 448996 3328 0 4920
190460
-/+ buffers/cache: 253616 198708
Swap: 787144 64 787080
root 1906 99.9 41.5 190912 188132 ttyp1 R+ 15:46 1:09
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
root 1922 0.0 0.0 1344 440 ttyp0 R+ 15:47 0:00 grep
php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:47:36 EST 2005
total used free shared buffers
cached
Mem: 452324 449316 3008 0 4872
159064
-/+ buffers/cache: 285380 166944
Swap: 787144 64 787080
root 1906 99.9 48.7 223104 220320 ttyp1 R+ 15:46 1:22
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:48:26 EST 2005
total used free shared buffers
cached
Mem: 452324 449508 2816 0 1036
35880
-/+ buffers/cache: 412592 39732
Swap: 787144 64 787080
root 1906 99.9 78.3 357200 354420 ttyp1 R+ 15:46 2:13
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
root 1930 0.0 0.0 1344 444 ttyp0 S+ 15:48 0:00 grep
php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 15:48:56 EST 2005
total used free shared buffers
cached
Mem: 452324 448796 3528 0 80
8272
-/+ buffers/cache: 440444 11880
Swap: 787144 75912 711232
root 1906 99.9 81.1 435200 366960 ttyp1 R+ 15:46 2:41
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
root 1934 0.0 0.0 1344 444 ttyp0 S+ 15:49 0:00 grep
php
ludo:~/tmp/php-5.1-dev# date; free; ps auxw | grep php
Fri Jul 8 16:00:25 EST 2005
total used free shared buffers
cached
Mem: 452324 449584 2740 0 80
1076
-/+ buffers/cache: 448428 3896
Swap: 787144 787144 0
root 1906 42.7 95.1 1216916 430252 ttyp1 T 15:46 7:40
/root/tmp/php-5.1-dev/php5-200507080430/sapi/cli/php
./poss-memory-leak.php
root 1957 0.0 0.0 1348 320 ttyp0 S+ 16:01 0:00 grep
php
=================================================================
After 14 minutes the box was thrashing to disk and was extremely slow
to respond. Suspending the script (ctrl-Z), and checking the output of
'top' showed that php was using around a gigabyte of RAM:
=================================================================
Tasks: 40 total, 2 running, 37 sleeping, 1 stopped, 0 zombie
Cpu(s): 0.3% us, 0.0% sy, 0.0% ni, 97.3% id, 2.3% wa, 0.0% hi,
0.0% si
Mem: 452324k total, 446624k used, 5700k free, 448k
buffers
Swap: 787144k total, 787144k used, 0k free, 5008k
cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1906 root 18 0 1188m 419m 4200 T 0.0 95.0 7:40.77 php
2398 root 16 0 1788 960 1664 R 0.0 0.2 0:00.06 top
861 root 16 0 6460 592 6016 R 0.0 0.1 0:03.96 sshd
877 root 16 0 2244 424 2080 S 0.0 0.1 0:01.67 bash
[ ... snip ... ]
=================================================================
And when left running, it eventually gives out-of-memory messages like
this in the kernel log:
=================================================================
Jul 7 17:49:37 ludo kernel: Out of Memory: Killed process 818
(apache).
Jul 7 17:50:25 ludo kernel: Out of Memory: Killed process 819
(apache).
Jul 7 17:53:34 ludo kernel: Out of Memory: Killed process 861
(apache).
Jul 7 17:57:50 ludo kernel: Out of Memory: Killed process 573
(mysqld).
Jul 7 17:57:50 ludo kernel: Out of Memory: Killed process 575
(mysqld).
Jul 7 17:57:50 ludo kernel: Out of Memory: Killed process 576
(mysqld).
Jul 7 17:57:50 ludo kernel: Out of Memory: Killed process 577
(mysqld).
Jul 7 18:02:58 ludo kernel: Out of Memory: Killed process 1284
(apache).
Jul 7 18:03:17 ludo kernel: Out of Memory: Killed process 1285
(apache).
Jul 7 18:03:23 ludo kernel: Out of Memory: Killed process 1259 (php).
=================================================================
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33614&edit=1