|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33127 fsockopen memory leak
Submitted: 2005-05-24 16:43 UTC Modified: 2005-05-25 11:25 UTC
From: joropito at ciudad dot com dot ar Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.0.4 OS: FreeBSD 5.3/4
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 !
Your email address:
Solve the problem:
41 - 11 = ?
Subscribe to this entry?

 [2005-05-24 16:43 UTC] joropito at ciudad dot com dot ar
I see that fsockopen() causes a memory leak although of closing filedescriptor.

Reproduce code:
  system("/bin/ps -maxwvj -p ".posix_getpid());
  $fd = fsockopen("", 80, $errno, $errstr, 3);
  system("/bin/ps -maxwvj -p ".posix_getpid());
  if($fd) {
    $out = "GET / HTTP/1.1\nHost: Close\n\n";
    fwrite($fd, $out);
    $line = "";
    while (!feof ($fd)) {
      $lastline = fgets($fd);
      $line .= $lastline;
      if(ereg("Content-Type: text/html", $lastline)) { break; }
    echo $line;
  system("/bin/ps -maxwvj -p ".posix_getpid());

Expected result:
You will see after issue fsockopen() memory usage rises, and if you issue fclose() does not free memory.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-24 16:50 UTC] joropito at ciudad dot com dot ar
Reproducible under php-4.3.9

Smaller reproducible code

  system("/bin/ps -l -p ".posix_getpid());
  $fd = fsockopen("", 80, $errno, $errstr, 3);
  system("/bin/ps -l -p ".posix_getpid());
  if($fd) fclose($fd);
  system("/bin/ps -l -p ".posix_getpid());
 [2005-05-24 18:10 UTC] joropito at ciudad dot com dot ar
It's related to any network interaction.
Reproducible with
file_get_contents (http wrapper)
 [2005-05-24 22:27 UTC]
How are you measuring this?
 [2005-05-25 00:56 UTC] joropito at ciudad dot com dot ar
This example code show initial and final memory usage. I'm wrong? It doesnt free all resources.
My cli application makes an infitite loop, and every time it tries to use network resources, memory usage increases and after some time no more memory available.

echo memory_get_usage()."\n";
$db = mysql_connect("dbhost", "dbuser", "dbpass");
echo memory_get_usage()."\n";
 [2005-05-25 11:25 UTC]
Yes, this is just how resources in PHP works. No bug here.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 07:05:45 2022 UTC