ID:               40222
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tdondich at groundworkopensource dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Apache2 related
 Operating System: Ubuntu Edgy
 PHP Version:      5.2.0
 New Comment:

>Can you please clarify how the session saving is taking
>more than 3 times the memory usage the script says it's >using?

You have that array in memory and a buffer which constantly grows. To
grow the buffer you need to allocate another one, bigger then the
previous, to copy data into it and free the small buffer. So in edge
case, there will be array + small buf + big buf in the memory in one
moment.


Previous Comments:
------------------------------------------------------------------------

[2007-01-24 21:51:59] haroldp at sierraweb dot com

I added some extra debug info to the script:

<?php
        session_start();
        $myarray = array();
        $numOfIterations = 1000000;  // Set to 10000 to see the script
succeed
        for($counter = 0; $counter < $numOfIterations; $counter++) {
                $myarray[$counter] =
                        
'jkdfjklsdfjklfsdhjklsdfhildfnifsdnsdfnlfsdnklfsdnkglgfnkl;nmklsdf';
                if ( ($counter % 100000) == 0) {
                        echo("Iterations: $counter, Memory: " . 
memory_get_usage() .
"<br>\n");
                }
        }
        // copy the array, just for kicks
        $_SESSION['test'] = $myarray;
        echo("USAGE: " . memory_get_usage() . "<br>\n");
        echo("Writing Session Data.");
        session_write_close();
        echo("Completed.");
?>

And the output is:

Iterations: 0, Memory: 42336
Iterations: 100000, Memory: 20291200
Iterations: 200000, Memory: 40539976
Iterations: 300000, Memory: 61837196
Iterations: 400000, Memory: 81037264
Iterations: 500000, Memory: 100237332
Iterations: 600000, Memory: 123631704
Iterations: 700000, Memory: 142831772
Iterations: 800000, Memory: 162031840
Iterations: 900000, Memory: 181231908
USAGE: 200431716
Writing Session Data.
Fatal error: Out of memory (allocated 532152320) (tried to allocate
1834294 bytes) in /usr/local/www/apache22/data/foo.php on line 16
Completed.

My environment is FreeBSD 6.2R, Apache 2.2.3, PHP 5.2.0, and 
memory_limit = 512M.

------------------------------------------------------------------------

[2007-01-24 21:40:05] tdondich at groundworkopensource dot com

If it was performing malloc/memcpy/free, in that order, then it would
be freeing the memory back via the free() system call.  Even if it's a
bogus test, it's a test to fit your requirements.  Can you please
clarify how the session saving is taking more than 3 times the memory
usage the script says it's using?

------------------------------------------------------------------------

[2007-01-24 21:32:34] [EMAIL PROTECTED]

Right, serializing is expected to consume even more memory, because it
has to run malloc/memcpy/free a lot.
Storing 256Mb in session is noway a real task and quite a bad test,
because it's not really clear what you're testing and what result you
want to get.

------------------------------------------------------------------------

[2007-01-24 21:29:35] tdondich at groundworkopensource dot com

UPDATE:

Modified the script:
<?php

session_start();
$myarray = array();

$numOfIterations = 1000000;
for($counter = 0; $counter < $numOfIterations; $counter++) {
  $myarray[$counter] =
'jkdfjklsdfjklfsdhjklsdfhildfnifsdnsdfnlfsdnklfsdnkglgfnkl;nmklsdf';
}

$_SESSION['test'] = $myarray;

print("SLEEPING<br />");
print("USAGE: " . memory_get_usage());
sleep(5);
?>

I receive this output:
SLEEPING
USAGE: 160289476
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 18874411 bytes) in Unknown on line 0

------------------------------------------------------------------------

[2007-01-24 21:26:56] tdondich at groundworkopensource dot com

I get this output with fatal error:
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 18874411 bytes) in Unknown on line 0

With this script:
<?php

session_start();
$myarray = array();

$numOfIterations = 1000000;
for($counter = 0; $counter < $numOfIterations; $counter++) {
  $myarray[$counter] =
'jkdfjklsdfjklfsdhjklsdfhildfnifsdnsdfnlfsdnklfsdnkglgfnkl;nmklsdf';
}

$_SESSION['test'] = $myarray;

print("SLEEPING<br />");
sleep(5);
?>


Because you get the SLEEPING output, it appears the high memory
consumption is occurring when the script has finished, possibly when
the session is trying to be serialized.

I'm running with PHP Version 5.2.1RC4-dev

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/40222

-- 
Edit this bug report at http://bugs.php.net/?id=40222&edit=1

Reply via email to