Location: PHPKode > scripts > HostingBenchmark > hostingbenchmark/tests/FileTest.php
<?php

/***************************************************************
*  (c) 2006-2007 Askywhale (hosting[a]askywhale.com)
*  All rights reserved
*
*  This script is part of HostingBenchmark.com. This project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
***************************************************************/

define('FILETEST_BASE_ITERATIONS',15);

class FileTest extends AbstractTest {
  function getTitle(){ return "File Test"; }
  function getDescription(){ return "Will open, read, write files from/to [tmp] folder"; }
  function getDefaultOn(){ return true; }
  function isBenchmark(){ return true; }
  function doTest(){ 
    $this->txtResult = OK_STR;
    for($i=0;$i<FILETEST_BASE_ITERATIONS;$i++) {      
      $dirname = get_cfg_var('upload_tmp_dir'); 
      if($dirname=="") {
        $dirname = "tmp_filetest";        
      }
      if(!file_exists($dirname)) {
        if(!@mkdir($dirname,0777)) {
          $this->txtResult = "Failed creating tmp directory. ".
            "Please create 0777 directory ".
            $dirname." in the root directory (beside images/ and includes/)";
          return;
        }          
      }  
      $fname = $dirname.'/hostingbenchmarktest'.$i.'.bin';
      $f = @fopen($fname,'w');
      if($f==false) {
        $this->txtResult = "Failed opening (w) ".$fname;
        return;    
      }
      for($j=0;$j<100;$j++) {
        $s = md5($j);
        for($k=0;$k<100;$k++)
          fputs($f,$s);
      }
      fclose($f);
      for($i2=0;$i2<20;$i2++) {
        $f = @fopen($fname,'r');
        if($f==false) {
          $this->txtResult = "Failed opening (r) ".$fname;
          return;    
        }
        $length = 0;
        while($s=fgets($f))
          $length += strlen($s);
        if($length<1000) {
          $this->txtResult = "Failed reading ".$fname;
          return;    
        }
        fclose($f); 
      }
      @unlink($fname);
    }    
  }
  function getTxtResults(){ 
    return $this->txtResult; 
  }
}

?>
Return current item: HostingBenchmark