php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28260 readfile + session_start results in huge memory consumption
Submitted: 2004-05-03 15:16 UTC Modified: 2004-05-11 20:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mb at diderot dot de Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.6 OS: Linux
Private report: No CVE-ID: None
 [2004-05-03 15:16 UTC] mb at diderot dot de
Description:
------------
When using readfile or fread in combination with 
session_start php seems to allocate memory for the whole 
filesize. Without session_start it doesn't. 
 
Replacing readfile by a fread loop doesn't make any 
difference. 
 

Reproduce code:
---------------
<?php
 //error appears:
 session_start();
 readfile('big.zip'); //big.zip > memory_limit
?>

<?php
 //working fine:
 readfile('big.zip'); //big.zip > memory_limit
?>

<?php
  //fread version, same error
  session_start();
  $fp = fopen('big.zip');
  while($d = fread($fp,4096)) {
    echo $d;
    flush();
  }
?>

Expected result:
----------------
Memory consumation should stay much bellow the whole 
filesize as it does without sessions. 

Actual result:
--------------
apache error.log: 
Allowed memory size of 16777216 bytes exhausted (tried to 
allocate 138188800 bytes) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-03 16:05 UTC] mb at diderot dot de
With php5 this just works fine ;)
 [2004-05-10 20:13 UTC] iliaa@php.net
Are you sure you don't have output buffering of any sort 
enabled? 
 [2004-05-11 17:50 UTC] mb at diderot dot de
I used flush() to prevent buffering. What surprises me is that it works in php5 without settings.
 [2004-05-11 20:26 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When using buffer, data inside the buffer will not be freed 
right away. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC