|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34471 fread() allocates length bytes without releasing unneeded
Submitted: 2005-09-12 03:03 UTC Modified: 2005-09-12 03:21 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: wojtek at wojjie dot com Assigned:
Status: Wont fix Package: Performance problem
PHP Version: 5.0.5 OS: Gentoo/Fedora
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
37 - 22 = ?
Subscribe to this entry?

 [2005-09-12 03:03 UTC] wojtek at wojjie dot com
fread() seems to allocate length amount of memory for getting data from the connection, but does not release it till you do something to variable. If $dat did have data, and you did:


It would then release any unused memory. 

Not sure if this is a bug, but I thought I would submit it incase.

Reproduce code:
$fp=fsockopen('udp://', 27015, $errno, $errstr);
stream_set_blocking($fp, false);
$dat=fread($fp, 4096000);
echo strlen($dat)."\n";
echo (memory_get_usage()-$bmem)."\n";


Expected result:
Difference in memory usage should not be so huge as 4095896 bytes.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-12 03:21 UTC]
That's the way fread() works.
Use stream_get_contents() instead.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 15:01:34 2024 UTC