Bug #18481: Upgrade from 4.0.6 to 4.2.2 Breaks sort() and/or opendir()

From: Date: Tue, 23 Jul 2002 00:58:37 +0000
Subject: Bug #18481: Upgrade from 4.0.6 to 4.2.2 Breaks sort() and/or opendir()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14822@lists.php.net to get a copy of this message
From:             van@armor-e.net
Operating system: Linux 2.2.20 on Alpha
PHP version:      4.2.1
PHP Bug Type:     Directory function related
Bug description:  Upgrade from 4.0.6 to 4.2.2 Breaks sort() and/or opendir()

The script below lists files in the current directory, which are mrtg html
and image output files.  The directory listing is parsed for the host name
and a row for each host is rendered with traffic, cpu, and uptime html and
image files on the corresponding row.  
Prior to upgrading from 4.0.6 to 4.2.2 the following script produced
correct output.  After upgrading, multiple rows for each host are output
in no specific order.  Here's the broken application:
http://tempe.dedserius.com/mrtg/

I took the application to an i386 server configured identically and tested
it and it worked fine:
http://winslow.dedserius.com/mrtg/
================================================================================
<table align="center" border=0 width="80%">
<%
    $handle=opendir('.');
    $colcount=0;
%>
  <tr bgcolor="#cccccc">
    <td align=center><!--mstheme--><font face="Century Gothic, Arial,
Helvetica"><STRONG>Host</STRONG><!--mstheme--></font></td>
    <td align=center><!--mstheme--><font face="Century Gothic, Arial,
Helvetica"><STRONG>Traffic</STRONG><!--mstheme--></font></td>
    <td align=center><!--mstheme--><font face="Century Gothic, Arial,
Helvetica"><STRONG>CPU</STRONG><!--mstheme--></font></td>
    <td align=center><!--mstheme--><font face="Century Gothic, Arial,
Helvetica"><STRONG>Uptime</STRONG><!--mstheme--></font></td>
  </tr>
<%
    while ($file = readdir($handle))
    {
    // Get the host name
    $host = substr($file,0,strpos($file,"."));
    if ( $host == "why" || $host == "cisco" || $host == "winslow"
      || $host == "yuma" || $host == "sedona"
      || $host == "tempe" || $host == "scottsdale"
      || $host == "vanboers" || $host == "sedonant" )
    {
      if ($host != $tmphost )
      {
        $i++;
        $fArray[$i] = array(
          "host"=>"$host");
      }
    $tmphost = $host;
    }
  }
  sort($fArray);
  closedir($handle);
  $cnt=0;
  for ($j=0; $j < count($fArray); $j++)
  {
    if ($fArray[$j][host] != $fArray[$j-1][host])
    {
      if ( ($cnt/2) == round($cnt/2))
      {
        $bgcolor="#ccccff";
      } else {
        $bgcolor="#ccddff";
      }
      echo "<tr bgcolor=\"$bgcolor\">\n";
      echo "<td><b>".$j." |
".ucfirst($fArray[$j][host])."</b></td>\n";
      switch ($fArray[$j][host])
      {
        case "why";
          echo "<td align=\"center\"><a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0.pub.html\">";
          echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0.pub-day.png\"
border=0
            alt=\"".$fArray[$j][host]." Daily Public Traffic\"
width=\"100\" height=\"50\"></a>&nbsp;";
          echo "<a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth1.priv.html\">";
          echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth1.priv-day.png\"
border=0
            alt=\"".$fArray[$j][host]." Daily Private Traffic\"
width=\"100\" height=\"50\"></a>";
          echo "</td>";
          break;
        case "cisco";
          echo "<td align=\"center\"><a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0.html\">";
          echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0-day.png\"
border=0
            alt=\"".$fArray[$j][host]." Daily Private Traffic\"
width=\"100\" height=\"50\"></a>&nbsp;";
          echo "<a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".ppp0.html\">";
          echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".ppp0-day.png\"
border=0
            alt=\"".$fArray[$j][host]." Daily Public Traffic\"
width=\"100\" height=\"50\"></a>";
          echo "</td>";
          break;
        default;
          echo "<td align=\"center\"><a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0.html\">";
          echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".eth0-day.png\"
border=0
            alt=\"".$fArray[$j][host]." Daily Traffic\" width=\"200\"
height=\"50\"></a></td>";
          break;
      }
      echo "<td align=\"center\"><a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".cpu.html\">";
                  echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".cpu-day.png\"
border=0
        alt=\"".$fArray[$j][host]." Daily CPU\" width=\"200\"
height=\"50\"></a></td>";
      echo "<td align=\"center\"><a
href=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".uptime.html\">";
      echo "<img
src=\"http://".$HTTP_HOST."/mrtg/".$fArray[$j][host].".uptime-month.png\"
border=0
         alt=\"".$fArray[$j][host]." Daily Uptime\" width=\"200\"
height=\"50\"></a></td>";
      echo "</tr>\n";
      $cnt++;
    }
}
%>
        <tr bgcolor="#cccccc">
                <td align=center><!--mstheme--><font face="Century Gothic,
Arial, Helvetica">
      <STRONG>All</STRONG><!--mstheme--></font></td>
                <td align=center><!--mstheme--><font face="Century Gothic,
Arial, Helvetica">
      <STRONG><a href="http://<% echo
$HTTP_HOST."/mrtg/"%>all.traffic.html">Traffic</a></STRONG><!--mstheme--></font></td>
                <td align=center><!--mstheme--><font face="Century Gothic,
Arial, Helvetica">
      <STRONG><a href="http://<% echo
$HTTP_HOST."/mrtg/"%>all.cpu.html">CPU</a></STRONG><!--mstheme--></font></td>
                <td align=center><!--mstheme--><font face="Century Gothic,
Arial, Helvetica">
      <STRONG><a href="http://<% echo
$HTTP_HOST."/mrtg/"%>all.uptime.html">Uptime</a></STRONG><!--mstheme--></font></td>
        </tr>
<%
  echo "</table>";
================================================================================
./configure --with-apache=/usr/src/apache_1.3.26 --with-mysql=/usr/local
--with-gd=/usr/gd1.3 --with-snmp --enable-ucd-snmp-hack

-- 
Edit bug report at http://bugs.php.net/?id=18481&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=18481&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=18481&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=18481&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=18481&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18481&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=18481&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=18481&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=18481&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=18481&r=globals



Thread (4 messages)

« previous php.bugs (#14822) next »