php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9695 memory leak when using fsockopen & fclose
Submitted: 2001-03-12 02:26 UTC Modified: 2001-03-18 20:06 UTC
From: pack at lib dot ntust dot edu dot tw Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4pl1 OS: FreeBSD + AOLServer3.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pack at lib dot ntust dot edu dot tw
New email:
PHP Version: OS:

 

 [2001-03-12 02:26 UTC] pack at lib dot ntust dot edu dot tw
When I using PHP4 in AOLSerevr3.2 at FreeBSD,
It seems to get memory leak when I using fsockopen() & fclose(),
and the memory usage is gettiing bigger & bigger....
configure option --with libgcc.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-17 09:26 UTC] sas@php.net
Not reproducible.  The latest PHP CVS with AOLserver 3.3.1 on FreeBSD 4.3-BETA does not exhibit this behaviour. 
 [2001-03-18 20:06 UTC] pack at lib dot ntust dot edu dot tw
Here is my php script....
<? header("content-type: text/html; charset=big5"); ?>
<html>
<style type="text/css">
<!--
pre {font-family:'courier'; font-size:12pt; letter-spacing:1};
th {background-color: gold; text-align: center;};
td {background-color: #ffffe0; text-align: center;};
-->
</style>
<body background="/icon/ivory.jpg">
<center><h1><? if (isset($grp)) echo($grp) ?></h1></center>
<hr>
<?
if (isset($grp)) $group = $grp;
else {
  $group = "ntust.office.library";	
}
// news  server
$fd = fsockopen("news.ntust.edu.tw", 119, &$errno, &$errstr, 30);
if ( $fd ) {
  $s = 0;
  $c = 0;
  $out = "";
  set_socket_blocking ( $fd, false );
  do {
    $out = fgets ( $fd, 2500 );
    if ( ereg ( "^200", $out ) ) {
      $s = 0;
      $out = "";
      $c++;
    }
    else if ( ( $c > 0 ) && ( $out == "" ) ) { break; }
    else { $s++; }
    if ( $s == 9999 ) { break; }
  } while ( $out == "" );
  
  set_socket_blocking ( $fd, true );
  
  if (!isset($grp)) {
    listgroup($fd);
  }
  elseif (isset($mid)) {
    ReadBody($fd, $group ,$mid);
  }
  else {
    ReadSubject($fd, $group);
  }
  fputs ( $fd, "QUIT\n" );
  fclose( $fd );
  $fd = null;
}
else {
  echo "$errstr ($errno)<br>\n";
}	
?>
<hr>
</body>
</html>
<?
exit;
function listgroup($fp) {
  fputs ( $fp, "LIST ACTIVE ntust.*\n" );  
//  fputs ( $fp, "LIST\n" );  
  $output = fgets ( $fp, 2000 );
  if (! ereg( "^215", $output )) return; 
  echo("<table border=1 width=400 align=center>\n");
  echo("<tr><th>?s??</th><th>Post ?ƥ?</th></tr>\n");
  for($c=0 ; $c <=1000 ;$c++) {
    $output = fgets ( $fp, 200 );
    if ( ereg ( "^\.", $output ) ) break;
    list( $newsgrp, $num) = split(" |\t", $output, 2);
    $num = (int) ($num);
    if ($num ==0 ) continue;
    if ( ereg ( "\.library", $newsgrp ) ) 
     $item="<font color=red><b>$newsgrp</b></font>" ;  
    else if ( ereg ( "ntust", $newsgrp ) ) 
     $item=$newsgrp;
    else continue;
    if ($c%2 == 0) $COLOR='bisque'; else $COLOR='mintcream';    
    echo ("<tr bgcolor=$COLOR><td>$item</td><td>");
    echo ("<a href=\"libnews.php?grp=$newsgrp\">$num</a></td></tr>\n");
//    echo ("<a href=\"libnews.php?grp=$newsgrp\">$num</a></td></tr>\n");
  } 
  echo("</table>\n");
}


function ReadSubject($fp,$grp) {
  echo ("<pre>\n");
  fputs ( $fp, "GROUP $grp\n" );  
  $output = fgets ( $fp, 2000 );
  list( $stat, $num, $start, $end) = split(' ', $output, 5);
  if ($stat != '211') return; 

  $i = (int) $start;
  $j = (int) $end;

  for (; $i <= $j; $j--) {
   fputs ( $fp, "HEAD $j\n" );  
   for($c=0 ; $c <50 ;$c++) {
    $output = fgets ( $fp, 200 );
    if ( ereg ( "^\.|^423", $output ) ) break;
    if ( ereg ( "(^From):.*(\(.*\))\r", $output, $reg ) )  $from=$reg[2];
    if ( ereg ( "(^Subject): (.+)\r", $output, $reg ) )  $sbj=$reg[2];
    if ( ereg ( "(^Date):(.+ .+ .+ ).* GMT.*\n", $output, $reg ) )  $date=$reg[2];
   } 
   if (ereg ( "^\.", $output )) {
     if(isset($grp)) $glink = "&grp=" . $grp;
     else $glink = "";
     echo("<tt>$date</tt><a href=\"libnews.php?mid=". $j . $glink . "\">$sbj</a>$from\n");
   }
  }
  echo ("</pre>\n");
}


function ReadBody($fp,$grp,$mesgid) {
  echo ("<pre>\n");
  fputs ( $fp, "group $grp\n" );  
  $output = fgets ( $fp, 2000 );
  if (! ereg("^211", $output )) return;

  fputs ( $fp, "head $mesgid\n" );
  for($c=0 ; $c <=100 ;$c++) {
    $output = fgets ( $fp, 200 );
    if ( ereg ( "^\.|^423", $output ) ) break;
    if ( ereg ( "^From|^Subject|^Date", $output) ) echo "$output";
  }

  fputs ( $fp, "body $mesgid\n" );  
  $op = true;
  for($c=0 ; $c <=200 ;$c++) {
    $output = fgets ( $fp, 200 );
    if ( ereg ( "^222", $output ) ) continue;
    if ( ereg ( "^\.|^423", $output ) ) break;
//    if ( ereg ( "^--\r", $output ) ) $op = false;
    if ($op) echo ereg_replace("\[(;*[0-9]*)*m" , "", $output);
  } 
  echo ("</pre>\n");
}

//header("Cache-Control: no-cache, must-revalidate");           // HTTP/1.1
//header("Pragma: no-cache");                                   // HTTP/1.0
?>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 01 09:01:22 2020 UTC